Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow ts redeclaration with import = and var #14940

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/babel-parser/src/plugins/typescript/index.ts
Expand Up @@ -29,7 +29,6 @@ import {
BIND_TS_NAMESPACE,
BIND_TS_TYPE_IMPORT,
BIND_CLASS,
BIND_LEXICAL,
BIND_NONE,
BIND_FLAGS_TS_IMPORT,
} from "../../util/scopeflags";
Expand Down Expand Up @@ -1929,7 +1928,7 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
): N.TsImportEqualsDeclaration {
node.isExport = isExport || false;
node.id = this.parseIdentifier();
this.checkIdentifier(node.id, BIND_LEXICAL);
this.checkIdentifier(node.id, BIND_FLAGS_TS_IMPORT);
this.expect(tt.eq);
const moduleReference = this.tsParseModuleReference();
if (
Expand Down
@@ -0,0 +1,3 @@
module M { }
import a = M;
var a;
@@ -0,0 +1,60 @@
{
"type": "File",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":6,"index":33}},
"program": {
"type": "Program",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":6,"index":33}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "TSModuleDeclaration",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":12,"index":12}},
"id": {
"type": "Identifier",
"start":7,"end":8,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":8,"index":8},"identifierName":"M"},
"name": "M"
},
"body": {
"type": "TSModuleBlock",
"start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12}},
"body": []
}
},
{
"type": "TSImportEqualsDeclaration",
"start":13,"end":26,"loc":{"start":{"line":2,"column":0,"index":13},"end":{"line":2,"column":13,"index":26}},
"importKind": "value",
"isExport": false,
"id": {
"type": "Identifier",
"start":20,"end":21,"loc":{"start":{"line":2,"column":7,"index":20},"end":{"line":2,"column":8,"index":21},"identifierName":"a"},
"name": "a"
},
"moduleReference": {
"type": "Identifier",
"start":24,"end":25,"loc":{"start":{"line":2,"column":11,"index":24},"end":{"line":2,"column":12,"index":25},"identifierName":"M"},
"name": "M"
}
},
{
"type": "VariableDeclaration",
"start":27,"end":33,"loc":{"start":{"line":3,"column":0,"index":27},"end":{"line":3,"column":6,"index":33}},
"declarations": [
{
"type": "VariableDeclarator",
"start":31,"end":32,"loc":{"start":{"line":3,"column":4,"index":31},"end":{"line":3,"column":5,"index":32}},
"id": {
"type": "Identifier",
"start":31,"end":32,"loc":{"start":{"line":3,"column":4,"index":31},"end":{"line":3,"column":5,"index":32},"identifierName":"a"},
"name": "a"
},
"init": null
}
],
"kind": "var"
}
],
"directives": []
}
}
7 changes: 1 addition & 6 deletions scripts/parser-tests/typescript/allowlist.txt
Expand Up @@ -11,7 +11,7 @@ exportDeclarationsInAmbientNamespaces2.ts
multipleExports.ts


# 139 valid programs produced a parsing error
# 134 valid programs produced a parsing error

ArrowFunctionExpression1.ts
MemberAccessorDeclaration15.ts
Expand Down Expand Up @@ -57,8 +57,6 @@ duplicateIdentifierInCatchBlock.ts
duplicateLabel1.ts
duplicateLabel2.ts
duplicatePackage_withErrors.ts
duplicateVarAndImport.ts
duplicateVarAndImport2.ts
emptyGenericParamList.ts
emptyTypeArgumentList.ts
emptyTypeArgumentListWithNew.ts
Expand Down Expand Up @@ -91,13 +89,10 @@ gettersAndSettersErrors.ts
giant.ts
implementClausePrecedingExtends.ts
implementsClauseAlreadySeen.ts
importAndVariableDeclarationConflict1.ts
importAndVariableDeclarationConflict3.ts
importAndVariableDeclarationConflict4.ts
importAssertionNonstring.ts
importDeclWithClassModifiers.ts
importDeclWithDeclareModifierInAmbientContext.ts
importedModuleClassNameClash.ts
indexSignatureWithAccessibilityModifier.ts
indexSignatureWithInitializer1.ts
indexSignatureWithTrailingComma.ts
Expand Down