Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
Fix: scope for TSImportEqualsDeclaration (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 authored and platinumazure committed Nov 30, 2018
1 parent 8ff0ad1 commit c5ffad3
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
16 changes: 16 additions & 0 deletions analyze-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,22 @@ class Referencer extends OriginalReferencer {
this.MethodDefinition(node);
}

/**
* Process import equal declaration
* @param {TSImportEqualsDeclaration} node The TSImportEqualsDeclaration node to visit.
* @returns {void}
*/
TSImportEqualsDeclaration(node) {
const { name, moduleReference } = node;
if (name && name.type === "Identifier") {
this.currentScope().__define(
name,
new Definition("ImportBinding", name, node, null, null, null)
);
}
this.visit(moduleReference);
}

/**
* Process the global augmentation.
* 1. Set the global scope as the current scope.
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/scope-analysis/import-equals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import foo = require('bar')
95 changes: 95 additions & 0 deletions tests/lib/__snapshots__/scope-analysis.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4480,6 +4480,101 @@ Object {
}
`;

exports[`TypeScript scope analysis tests/fixtures/scope-analysis/import-equals.ts 1`] = `
Object {
"$id": 2,
"block": Object {
"range": Array [
0,
28,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 1,
"block": Object {
"range": Array [
0,
28,
],
"type": "Program",
},
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
"throughReferences": Array [],
"type": "module",
"upperScope": Object {
"$ref": 2,
},
"variableMap": Object {
"foo": Object {
"$ref": 0,
},
},
"variableScope": Object {
"$ref": 1,
},
"variables": Array [
Object {
"$id": 0,
"defs": Array [
Object {
"name": Object {
"name": "foo",
"range": Array [
7,
10,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
0,
27,
],
"type": "TSImportEqualsDeclaration",
},
"parent": null,
"type": "ImportBinding",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "foo",
"range": Array [
7,
10,
],
"type": "Identifier",
},
],
"name": "foo",
"references": Array [],
"scope": Object {
"$ref": 1,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [],
"type": "global",
"upperScope": null,
"variableMap": Object {},
"variableScope": Object {
"$ref": 2,
},
"variables": Array [],
}
`;

exports[`TypeScript scope analysis tests/fixtures/scope-analysis/interface-type.ts 1`] = `
Object {
"$id": 0,
Expand Down
2 changes: 2 additions & 0 deletions visitor-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ module.exports = Evk.unionWith({
TSEnumMember: ["id", "initializer"],
TSExportAssignment: ["expression"],
TSExportKeyword: [],
TSExternalModuleReference: ["expression"],
TSImportType: ["parameter", "qualifier", "typeParameters"],
TSLiteralType: ["literal"],
TSIndexSignature: ["typeAnnotation", "index"],
TSInterfaceBody: ["body"],
TSInterfaceDeclaration: ["id", "typeParameters", "heritage", "body"],
TSInterfaceHeritage: ["id", "typeParameters"],
TSImportEqualsDeclaration: ["name", "moduleReference"],
TSFunctionType: ["parameters", "typeAnnotation"],
TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"],
TSModuleBlock: ["body"],
Expand Down

0 comments on commit c5ffad3

Please sign in to comment.