Skip to content

Commit ec4863c

Browse files
authored
Fix37991 (#43166)
* Add failing test * Fix tslib check errors for commonjs imports
1 parent 9610c16 commit ec4863c

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -34678,8 +34678,8 @@ namespace ts {
3467834678
}
3467934679
}
3468034680

34681-
if (node.kind === SyntaxKind.BindingElement) {
34682-
if (node.parent.kind === SyntaxKind.ObjectBindingPattern && languageVersion < ScriptTarget.ESNext) {
34681+
if (isBindingElement(node)) {
34682+
if (isObjectBindingPattern(node.parent) && node.dotDotDotToken && languageVersion < ScriptTarget.ES2018) {
3468334683
checkExternalEmitHelpers(node, ExternalEmitHelpers.Rest);
3468434684
}
3468534685
// check computed properties inside property names of binding elements
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/compiler/main.js(2,25): error TS2307: Cannot find module 'bar' or its corresponding type declarations.
2+
3+
4+
==== tests/cases/compiler/main.js (1 errors) ====
5+
"use strict";
6+
const { foo } = require("bar");
7+
~~~~~
8+
!!! error TS2307: Cannot find module 'bar' or its corresponding type declarations.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/main.js ===
2+
"use strict";
3+
const { foo } = require("bar");
4+
>foo : Symbol(foo, Decl(main.js, 1, 7))
5+
>require : Symbol(require)
6+
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/main.js ===
2+
"use strict";
3+
>"use strict" : "use strict"
4+
5+
const { foo } = require("bar");
6+
>foo : any
7+
>require("bar") : any
8+
>require : any
9+
>"bar" : "bar"
10+

tests/cases/compiler/tslibInJs.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @checkJs: true
2+
// @allowJs: true
3+
// @moduleResolution: node
4+
// @target: es2018
5+
// @module: commonjs
6+
// @importHelpers: true
7+
// @lib: es2018
8+
// @outDir: out
9+
// @noEmit: true
10+
11+
// @fileName: main.js
12+
"use strict";
13+
const { foo } = require("bar");

0 commit comments

Comments
 (0)