diff --git a/lib/optimize/ConcatenatedModule.js b/lib/optimize/ConcatenatedModule.js index ff5fe0741..d0153ab8c 100644 --- a/lib/optimize/ConcatenatedModule.js +++ b/lib/optimize/ConcatenatedModule.js @@ -6,6 +6,7 @@ "use strict"; const eslintScope = require("eslint-scope"); +const Referencer = require("eslint-scope/lib/referencer"); const { CachedSource, ConcatSource, @@ -58,6 +59,14 @@ const { /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */ +// fix eslint-scope to support class properties correctly +// cspell:word Referencer +const ReferencerClass = Referencer; +if (!ReferencerClass.prototype.PropertyDefinition) { + ReferencerClass.prototype.PropertyDefinition = + ReferencerClass.prototype.Property; +} + /** * @typedef {Object} ReexportInfo * @property {Module} module diff --git a/package.json b/package.json index 10d693cde..39db23604 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "chrome-trace-event": "^1.0.2", "enhanced-resolve": "^5.8.0", "es-module-lexer": "^0.4.0", - "eslint-scope": "^5.1.1", + "eslint-scope": "5.1.1", "events": "^3.2.0", "glob-to-regexp": "^0.4.1", "graceful-fs": "^4.2.4", diff --git a/test/cases/parsing/class-properties/index.js b/test/cases/parsing/class-properties/index.js new file mode 100644 index 000000000..e81488eac --- /dev/null +++ b/test/cases/parsing/class-properties/index.js @@ -0,0 +1,21 @@ +import { A, B } from "./module"; +import { A as A1, B as B1 } from "./module?1"; + +it("should not rename class properties", function () { + expect(A.staticProp).toBe("value"); + expect(B.staticProp).toBe("value"); + expect(A1.staticProp).toBe("value"); + expect(B1.staticProp).toBe("value"); + expect(A.value).toBe("value"); + expect(B.value).toBe("value"); + expect(A1.value).toBe("value"); + expect(B1.value).toBe("value"); + expect(new A().prop).toBe("value"); + expect(new B().prop).toBe("value"); + expect(new A1().prop).toBe("value"); + expect(new B1().prop).toBe("value"); + expect(new A().value).toBe("value"); + expect(new B().value).toBe("value"); + expect(new A1().value).toBe("value"); + expect(new B1().value).toBe("value"); +}); diff --git a/test/cases/parsing/class-properties/module.js b/test/cases/parsing/class-properties/module.js new file mode 100644 index 000000000..8736c7ca1 --- /dev/null +++ b/test/cases/parsing/class-properties/module.js @@ -0,0 +1,21 @@ +import { + staticProp as importedStaticProp, + prop as importedProp +} from "./module"; + +export const staticProp = "value"; +export const prop = "value"; + +export class A { + static staticProp = staticProp; + static [staticProp] = staticProp; + prop = prop; + [prop] = prop; +} + +export class B { + static staticProp = importedStaticProp; + static [importedStaticProp] = importedStaticProp; + prop = importedProp; + [importedProp] = importedProp; +} diff --git a/test/cases/parsing/class-properties/test.filter.js b/test/cases/parsing/class-properties/test.filter.js new file mode 100644 index 000000000..25a2a20eb --- /dev/null +++ b/test/cases/parsing/class-properties/test.filter.js @@ -0,0 +1,5 @@ +var supportsClassFields = require("../../../helpers/supportsClassFields"); + +module.exports = function (config) { + return supportsClassFields(); +}; diff --git a/yarn.lock b/yarn.lock index 445c02f7c..f92c38862 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2563,7 +2563,7 @@ eslint-plugin-prettier@^3.1.4: dependencies: prettier-linter-helpers "^1.0.0" -eslint-scope@^5.0.0, eslint-scope@^5.1.1: +eslint-scope@5.1.1, eslint-scope@^5.0.0, eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==