Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit c5ffad3

Browse filesBrowse files
armano2platinumazure
authored andcommitted
Fix: scope for TSImportEqualsDeclaration (#571)
1 parent 8ff0ad1 commit c5ffad3
Copy full SHA for c5ffad3

File tree

Expand file treeCollapse file tree

4 files changed

+114
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+114
-0
lines changed

‎analyze-scope.js

Copy file name to clipboardExpand all lines: analyze-scope.js
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,22 @@ class Referencer extends OriginalReferencer {
610610
this.MethodDefinition(node);
611611
}
612612

613+
/**
614+
* Process import equal declaration
615+
* @param {TSImportEqualsDeclaration} node The TSImportEqualsDeclaration node to visit.
616+
* @returns {void}
617+
*/
618+
TSImportEqualsDeclaration(node) {
619+
const { name, moduleReference } = node;
620+
if (name && name.type === "Identifier") {
621+
this.currentScope().__define(
622+
name,
623+
new Definition("ImportBinding", name, node, null, null, null)
624+
);
625+
}
626+
this.visit(moduleReference);
627+
}
628+
613629
/**
614630
* Process the global augmentation.
615631
* 1. Set the global scope as the current scope.
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import foo = require('bar')

‎tests/lib/__snapshots__/scope-analysis.js.snap

Copy file name to clipboardExpand all lines: tests/lib/__snapshots__/scope-analysis.js.snap
+95Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4480,6 +4480,101 @@ Object {
44804480
}
44814481
`;
44824482

4483+
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/import-equals.ts 1`] = `
4484+
Object {
4485+
"$id": 2,
4486+
"block": Object {
4487+
"range": Array [
4488+
0,
4489+
28,
4490+
],
4491+
"type": "Program",
4492+
},
4493+
"childScopes": Array [
4494+
Object {
4495+
"$id": 1,
4496+
"block": Object {
4497+
"range": Array [
4498+
0,
4499+
28,
4500+
],
4501+
"type": "Program",
4502+
},
4503+
"childScopes": Array [],
4504+
"functionExpressionScope": false,
4505+
"isStrict": true,
4506+
"references": Array [],
4507+
"throughReferences": Array [],
4508+
"type": "module",
4509+
"upperScope": Object {
4510+
"$ref": 2,
4511+
},
4512+
"variableMap": Object {
4513+
"foo": Object {
4514+
"$ref": 0,
4515+
},
4516+
},
4517+
"variableScope": Object {
4518+
"$ref": 1,
4519+
},
4520+
"variables": Array [
4521+
Object {
4522+
"$id": 0,
4523+
"defs": Array [
4524+
Object {
4525+
"name": Object {
4526+
"name": "foo",
4527+
"range": Array [
4528+
7,
4529+
10,
4530+
],
4531+
"type": "Identifier",
4532+
},
4533+
"node": Object {
4534+
"range": Array [
4535+
0,
4536+
27,
4537+
],
4538+
"type": "TSImportEqualsDeclaration",
4539+
},
4540+
"parent": null,
4541+
"type": "ImportBinding",
4542+
},
4543+
],
4544+
"eslintUsed": undefined,
4545+
"identifiers": Array [
4546+
Object {
4547+
"name": "foo",
4548+
"range": Array [
4549+
7,
4550+
10,
4551+
],
4552+
"type": "Identifier",
4553+
},
4554+
],
4555+
"name": "foo",
4556+
"references": Array [],
4557+
"scope": Object {
4558+
"$ref": 1,
4559+
},
4560+
},
4561+
],
4562+
},
4563+
],
4564+
"functionExpressionScope": false,
4565+
"isStrict": false,
4566+
"references": Array [],
4567+
"throughReferences": Array [],
4568+
"type": "global",
4569+
"upperScope": null,
4570+
"variableMap": Object {},
4571+
"variableScope": Object {
4572+
"$ref": 2,
4573+
},
4574+
"variables": Array [],
4575+
}
4576+
`;
4577+
44834578
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/interface-type.ts 1`] = `
44844579
Object {
44854580
"$id": 0,

‎visitor-keys.js

Copy file name to clipboardExpand all lines: visitor-keys.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ module.exports = Evk.unionWith({
4444
TSEnumMember: ["id", "initializer"],
4545
TSExportAssignment: ["expression"],
4646
TSExportKeyword: [],
47+
TSExternalModuleReference: ["expression"],
4748
TSImportType: ["parameter", "qualifier", "typeParameters"],
4849
TSLiteralType: ["literal"],
4950
TSIndexSignature: ["typeAnnotation", "index"],
5051
TSInterfaceBody: ["body"],
5152
TSInterfaceDeclaration: ["id", "typeParameters", "heritage", "body"],
5253
TSInterfaceHeritage: ["id", "typeParameters"],
54+
TSImportEqualsDeclaration: ["name", "moduleReference"],
5355
TSFunctionType: ["parameters", "typeAnnotation"],
5456
TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"],
5557
TSModuleBlock: ["body"],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.