Skip to content

Commit

Permalink
Use jsonc parser to parse a config file
Browse files Browse the repository at this point in the history
This fixes a problem where the `typescript` VSCode task runs `tsc` with `-p`
when it should run `-b` when `tsconfig.json` has the `"references"` property.

```js
{
  "extends": "./tsconfig.app.json",
  // meow
  "references": [{ "path": "./tsconfig.lib.json" }]
}
```

This bug happens because while `tsconfig.json` file allows comment, the
parsing logic here uses vanilla `JSON.parse` which cannot parse comments.

This commit fixes it by using `jsonc.parse` instead.
  • Loading branch information
dtinth authored Jan 30, 2019
1 parent 4aa8c83 commit 84424c8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extensions/typescript-language-features/src/features/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import * as jsonc from 'jsonc-parser';
import { ITypeScriptServiceClient } from '../typescriptService';
import { Lazy } from '../utils/lazy';
import { isImplicitProjectConfigFile } from '../utils/tsconfig';
Expand Down Expand Up @@ -217,7 +218,7 @@ class TscTaskProvider implements vscode.TaskProvider {
}

try {
const tsconfig = JSON.parse(result.toString());
const tsconfig = jsonc.parse(result.toString());
if (tsconfig.references) {
return resolve(['-b', project.path]);
}
Expand Down

0 comments on commit 84424c8

Please sign in to comment.