acorn-class-fields
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -84,3 +84,3 @@ { | ||
"getter-return": "error", | ||
"global-require": "error", | ||
"global-require": "warn", | ||
"guard-for-in": "error", | ||
@@ -134,3 +134,3 @@ "handle-callback-err": "error", | ||
"no-await-in-loop": "error", | ||
"no-bitwise": "error", | ||
"no-bitwise": "off", | ||
"no-buffer-constructor": "error", | ||
@@ -137,0 +137,0 @@ "no-caller": "error", |
@@ -0,1 +1,10 @@ | ||
## 0.3.2 (2020-04-24) | ||
* Make compatible with acorn@7 | ||
* Use injected acorn instance if available | ||
* Evaluate class heritage with outer private environment | ||
* Don't allow private element access on `super` | ||
* Uses `Object.getPrototypeOf` if available instead of `__proto__` | ||
* Fix usage of super in field initializers | ||
## 0.3.1 (2019-02-09) | ||
@@ -2,0 +11,0 @@ |
27
index.js
"use strict" | ||
const acorn = require("acorn") | ||
const tt = acorn.tokTypes | ||
const privateClassElements = require("acorn-private-class-elements") | ||
function maybeParseFieldValue(field) { | ||
if (this.eat(tt.eq)) { | ||
const oldInFieldValue = this._inFieldValue | ||
this._inFieldValue = true | ||
field.value = this.parseExpression() | ||
this._inFieldValue = oldInFieldValue | ||
} else field.value = null | ||
} | ||
module.exports = function(Parser) { | ||
const acorn = Parser.acorn || require("acorn") | ||
const tt = acorn.tokTypes | ||
module.exports = function(Parser) { | ||
Parser = privateClassElements(Parser) | ||
return class extends Parser { | ||
_maybeParseFieldValue(field) { | ||
if (this.eat(tt.eq)) { | ||
const oldInFieldValue = this._inFieldValue | ||
this._inFieldValue = true | ||
field.value = this.parseExpression() | ||
this._inFieldValue = oldInFieldValue | ||
} else field.value = null | ||
} | ||
// Parse fields | ||
@@ -42,3 +43,5 @@ parseClassElement(_constructorAllowsSuper) { | ||
} | ||
maybeParseFieldValue.call(this, node) | ||
this.enterScope(64 | 2 | 1) // See acorn's scopeflags.js | ||
this._maybeParseFieldValue(node) | ||
this.exitScope() | ||
this.finishNode(node, "FieldDefinition") | ||
@@ -45,0 +48,0 @@ this.semicolon() |
@@ -22,16 +22,16 @@ { | ||
"peerDependencies": { | ||
"acorn": "^6.0.0" | ||
"acorn": "^6.0.0 || ^7.0.0" | ||
}, | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"devDependencies": { | ||
"acorn": "^6.1.0", | ||
"eslint": "^5.13.0", | ||
"eslint-plugin-node": "^8.0.1", | ||
"mocha": "^5.2.0", | ||
"test262": "git+https://github.com/tc39/test262.git#33a306d1026b72227eb50a918db19ada16f12b3d", | ||
"acorn": "^6.0.0 || ^7.0.0", | ||
"eslint": "^6", | ||
"eslint-plugin-node": "^11", | ||
"mocha": "^7", | ||
"test262": "git+https://github.com/tc39/test262.git#57fa74b170e9554bfe89a29c10de2447fe7d3b27", | ||
"test262-parser-runner": "^0.5.0" | ||
}, | ||
"dependencies": { | ||
"acorn-private-class-elements": "^0.1.1" | ||
"acorn-private-class-elements": "^0.2.5" | ||
} | ||
} |
@@ -10,7 +10,7 @@ "use strict" | ||
const unsupportedFeatures = [ | ||
"BigInt", | ||
"class-methods-private", | ||
"class-static-fields-public", | ||
"class-static-fields-private", | ||
"class-static-methods-private" | ||
"class-static-methods-private", | ||
"optional-chaining" | ||
] | ||
@@ -21,3 +21,3 @@ | ||
run( | ||
(content, options) => Parser.parse(content, {sourceType: options.sourceType, ecmaVersion: 9}), | ||
(content, options) => Parser.parse(content, {sourceType: options.sourceType, ecmaVersion: 11}), | ||
{ | ||
@@ -24,0 +24,0 @@ testsDirectory: path.dirname(require.resolve("test262/package.json")), |
@@ -29,2 +29,6 @@ "use strict" | ||
describe("acorn-class-fields", function () { | ||
test(`class P extends Q { | ||
x = super.x | ||
}`) | ||
test(`class Counter extends HTMLElement { | ||
@@ -42,2 +46,18 @@ x = 0; | ||
test(` | ||
class AsyncIterPipe{ | ||
static get [ Symbol.species](){ | ||
return Promise | ||
} | ||
static get Closing(){ | ||
return Closing | ||
} | ||
static get controllerSignals(){ return controllerSignals} | ||
static get listenerBinding(){ return listenerBinding} | ||
// state | ||
done= false | ||
} | ||
`) | ||
test(`class Counter extends HTMLElement { | ||
@@ -63,3 +83,3 @@ #x = 0; | ||
testFail("class A { a = () => arguments }", "A class field initializer may not contain arguments (1:20)") | ||
testFail("class A { a = () => super() }", "'super' keyword outside a method (1:20)") | ||
testFail("class A { a = () => super() }", "super() call outside constructor of a subclass (1:20)") | ||
testFail("class A { # a }", "Unexpected token (1:10)") | ||
@@ -66,0 +86,0 @@ testFail("class A { #a; a() { this.# a } }", "Unexpected token (1:27)") |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25823
722
+ Addedacorn@7.4.1(transitive)
+ Addedacorn-private-class-elements@0.2.7(transitive)
- Removedacorn@6.4.2(transitive)
- Removedacorn-private-class-elements@0.1.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbrowser-stdout@1.3.1(transitive)
- Removedcommander@2.15.1(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddebug@3.1.0(transitive)
- Removeddiff@3.5.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.1.2(transitive)
- Removedgrowl@1.10.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhe@1.1.1(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@3.0.4(transitive)
- Removedminimist@0.0.8(transitive)
- Removedmkdirp@0.5.1(transitive)
- Removedmocha@5.2.0(transitive)
- Removedms@2.0.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedsupports-color@5.4.0(transitive)
- Removedwrappy@1.0.2(transitive)