Skip to content

Commit

Permalink
fix #279: resolve implicit tsconfig.json base file
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 28, 2020
1 parent 4520605 commit fb36385
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

Syntax trees with millions of sequential binary operators nested inside each other can cause the parser to stack overflow because it uses a recursive visitor pattern, so each binary operator added an entry to the call stack. Now code like this no longer triggers a stack overflow because the visitor uses the heap instead of the stack in this case. This is unlikely to matter in real-world code but can show up in certain artificial test cases, especially when `--minify-syntax` is enabled.

* Resolve implicitly-named `tsconfig.json` base files ([#279](https://github.com/evanw/esbuild/issues/279))

The official TypeScript compiler lets you specify a package path as the `extends` property of a `tsconfig.json` file. The base file is then searched for in the relevant `node_modules` directory. Previously the package path had to end with the name of the base file. Now you can additionally omit the name of the base file if the file name is `tsconfig.json`. This more closely matches the behavior of the official TypeScript compiler.

## 0.6.8

* Attempt to support the taobao.org registry ([#291](https://github.com/evanw/esbuild/issues/291))
Expand Down
33 changes: 33 additions & 0 deletions internal/bundler/bundler_tsconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,36 @@ console.log("good");
},
})
}

func TestTsconfigJsonNodeModulesImplicitFile(t *testing.T) {
expectBundled(t, bundled{
files: map[string]string{
"/Users/user/project/src/app/entry.tsx": `
console.log(<div/>)
`,
"/Users/user/project/src/tsconfig.json": `
{
"extends": "foo"
}
`,
"/Users/user/project/src/node_modules/foo/tsconfig.json": `
{
"compilerOptions": {
"jsx": "react",
"jsxFactory": "worked"
}
}
`,
},
entryPaths: []string{"/Users/user/project/src/app/entry.tsx"},
options: config.Options{
IsBundling: true,
AbsOutputFile: "/Users/user/project/out.js",
},
expected: map[string]string{
"/Users/user/project/out.js": `// /Users/user/project/src/app/entry.tsx
console.log(/* @__PURE__ */ worked("div", null));
`,
},
})
}
5 changes: 3 additions & 2 deletions internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,9 @@ func (r *resolver) parseJsTsConfig(file string, visited map[string]bool) (*tsCon
for !found {
// Skip "node_modules" folders
if r.fs.Base(current) != "node_modules" {
extendsFile := r.fs.Join(current, "node_modules", extends)
for _, fileToCheck := range []string{extendsFile, extendsFile + ".json"} {
join := r.fs.Join(current, "node_modules", extends)
filesToCheck := []string{join, join + ".json", r.fs.Join(join, "tsconfig.json")}
for _, fileToCheck := range filesToCheck {
base, baseStatus := r.parseJsTsConfig(fileToCheck, visited)
if baseStatus == parseReadFailure {
continue
Expand Down

0 comments on commit fb36385

Please sign in to comment.