Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Update: support new export syntax (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored Jun 4, 2020
1 parent dbddf14 commit d4a3764
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/referencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,15 +593,26 @@ class Referencer extends esrecurse.Visitor {
this.visitChildren(node);
}

// TODO: ExportDeclaration doesn't exist. for bc?
ExportDeclaration(node) {
this.visitExportDeclaration(node);
}

ExportAllDeclaration(node) {
this.visitExportDeclaration(node);
}

ExportDefaultDeclaration(node) {
this.visitExportDeclaration(node);
}

ExportNamedDeclaration(node) {
this.visitExportDeclaration(node);
}

ExportSpecifier(node) {

// TODO: `node.id` doesn't exist. for bc?
const local = (node.id || node.local);

this.visit(local);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"eslint-config-eslint": "^5.0.1",
"eslint-plugin-node": "^9.1.0",
"eslint-release": "^1.0.0",
"espree": "^6.0.0",
"eslint-visitor-keys": "^1.2.0",
"espree": "^7.1.0",
"istanbul": "^0.4.5",
"mocha": "^6.1.4",
"npm-license": "^0.3.3",
Expand Down
37 changes: 37 additions & 0 deletions tests/export-star-as-ns-from-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict";

const assert = require("assert");
const espree = require("espree");
const { KEYS } = require("eslint-visitor-keys");
const { analyze } = require("../lib/index");

describe("export * as ns from 'source'", () => {
let scopes;

beforeEach(() => {
const ast = espree.parse("export * as ns from 'source'", {
ecmaVersion: 2020,
sourceType: "module"
});
const manager = analyze(ast, {
ecmaVersion: 11,
sourceType: "module",
childVisitorKeys: KEYS
});

scopes = [manager.globalScope, ...manager.globalScope.childScopes];
});

it("should not have any references", () => {
for (const scope of scopes) {
assert.strictEqual(scope.references.length, 0, scope.type);
assert.strictEqual(scope.through.length, 0, scope.type);
}
});

it("should not have any variables", () => {
for (const scope of scopes) {
assert.strictEqual(scope.variables.length, 0, scope.type);
}
});
});

0 comments on commit d4a3764

Please sign in to comment.