From 6e8dfe310e6f11d976117b611fe92ff167cbaf2c Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Sat, 28 Feb 2015 13:47:26 -0800 Subject: [PATCH] New: Support ES6 classes (refs #10) --- README.md | 5 +- espree.js | 344 ++++++++++++++--- lib/ast-node-factory.js | 45 ++- lib/ast-node-types.js | 4 + lib/features.js | 3 + lib/messages.js | 3 + test/3rdparty/syntax/README | 1 - tests/fixtures/ast/API.json | 308 ---------------- .../class-accessor-properties.result.js | 268 ++++++++++++++ .../classes/class-accessor-properties.src.js | 1 + .../class-computed-static-method.result.js | 170 +++++++++ .../class-computed-static-method.src.js | 1 + .../classes/class-expression.result.js | 73 ++++ .../classes/class-expression.src.js | 1 + .../class-method-named-prototype.result.js | 170 +++++++++ .../class-method-named-prototype.src.js | 1 + .../class-method-named-static.result.js | 170 +++++++++ .../classes/class-method-named-static.src.js | 1 + .../classes/class-one-method.result.js | 170 +++++++++ .../classes/class-one-method.src.js | 3 + ...ss-static-method-named-prototype.result.js | 171 +++++++++ ...class-static-method-named-prototype.src.js | 1 + ...class-static-method-named-static.result.js | 170 +++++++++ .../class-static-method-named-static.src.js | 1 + .../classes/class-static-method.result.js | 170 +++++++++ .../classes/class-static-method.src.js | 1 + ...-methods-and-accessor-properties.result.js | 347 ++++++++++++++++++ ...tic-methods-and-accessor-properties.src.js | 1 + ...lass-two-computed-static-methods.result.js | 249 +++++++++++++ .../class-two-computed-static-methods.src.js | 1 + ...two-methods-computed-constructor.result.js | 251 +++++++++++++ ...ss-two-methods-computed-constructor.src.js | 1 + .../classes/class-two-methods-semi.result.js | 249 +++++++++++++ .../classes/class-two-methods-semi.src.js | 1 + .../class-two-methods-three-semi.result.js | 249 +++++++++++++ .../class-two-methods-three-semi.src.js | 1 + .../class-two-methods-two-semi.result.js | 249 +++++++++++++ .../classes/class-two-methods-two-semi.src.js | 1 + .../classes/class-two-methods.result.js | 249 +++++++++++++ .../classes/class-two-methods.src.js | 1 + ...static-methods-named-constructor.result.js | 249 +++++++++++++ ...wo-static-methods-named-constructor.src.js | 1 + .../classes/class-with-constructor.result.js | 170 +++++++++ .../classes/class-with-constructor.src.js | 1 + .../derived-class-assign-to-var.result.js | 146 ++++++++ .../derived-class-assign-to-var.src.js | 1 + .../derived-class-expression.result.js | 91 +++++ .../classes/derived-class-expression.src.js | 1 + .../classes/empty-class-double-semi.result.js | 90 +++++ .../classes/empty-class-double-semi.src.js | 1 + .../classes/empty-class-semi.result.js | 90 +++++ .../classes/empty-class-semi.src.js | 1 + .../classes/empty-class.result.js | 90 +++++ .../ecma-features/classes/empty-class.src.js | 1 + .../empty-literal-derived-class.result.js | 108 ++++++ .../empty-literal-derived-class.src.js | 1 + .../invalid-super-global-call.result.js | 6 + .../classes/invalid-super-global-call.src.js | 1 + .../classes/named-class-expression.result.js | 90 +++++ .../classes/named-class-expression.src.js | 1 + .../named-derived-class-expression.result.js | 108 ++++++ .../named-derived-class-expression.src.js | 1 + ...-function-call-in-object-literal.result.js | 6 + ...per-function-call-in-object-literal.src.js | 6 + .../classes/super-function-call.result.js | 6 + .../classes/super-function-call.src.js | 3 + ...-property-call-in-object-literal.result.js | 6 + ...per-property-call-in-object-literal.src.js | 6 + .../classes/super-property-call.result.js | 6 + .../classes/super-property-call.src.js | 3 + tests/lib/ecma-features.js | 4 + 71 files changed, 5046 insertions(+), 355 deletions(-) delete mode 100644 test/3rdparty/syntax/README delete mode 100644 tests/fixtures/ast/API.json create mode 100644 tests/fixtures/ecma-features/classes/class-accessor-properties.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-accessor-properties.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-computed-static-method.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-computed-static-method.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-expression.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-expression.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-method-named-prototype.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-method-named-prototype.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-method-named-static.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-method-named-static.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-one-method.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-one-method.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-static-method-named-prototype.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-static-method-named-prototype.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-static-method-named-static.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-static-method-named-static.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-static-method.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-static-method.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-computed-static-methods.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-computed-static-methods.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-methods-semi.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-methods-semi.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-methods-three-semi.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-methods-three-semi.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-methods-two-semi.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-methods-two-semi.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-methods.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-methods.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-static-methods-named-constructor.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-two-static-methods-named-constructor.src.js create mode 100644 tests/fixtures/ecma-features/classes/class-with-constructor.result.js create mode 100644 tests/fixtures/ecma-features/classes/class-with-constructor.src.js create mode 100644 tests/fixtures/ecma-features/classes/derived-class-assign-to-var.result.js create mode 100644 tests/fixtures/ecma-features/classes/derived-class-assign-to-var.src.js create mode 100644 tests/fixtures/ecma-features/classes/derived-class-expression.result.js create mode 100644 tests/fixtures/ecma-features/classes/derived-class-expression.src.js create mode 100644 tests/fixtures/ecma-features/classes/empty-class-double-semi.result.js create mode 100644 tests/fixtures/ecma-features/classes/empty-class-double-semi.src.js create mode 100644 tests/fixtures/ecma-features/classes/empty-class-semi.result.js create mode 100644 tests/fixtures/ecma-features/classes/empty-class-semi.src.js create mode 100644 tests/fixtures/ecma-features/classes/empty-class.result.js create mode 100644 tests/fixtures/ecma-features/classes/empty-class.src.js create mode 100644 tests/fixtures/ecma-features/classes/empty-literal-derived-class.result.js create mode 100644 tests/fixtures/ecma-features/classes/empty-literal-derived-class.src.js create mode 100644 tests/fixtures/ecma-features/classes/invalid-super-global-call.result.js create mode 100644 tests/fixtures/ecma-features/classes/invalid-super-global-call.src.js create mode 100644 tests/fixtures/ecma-features/classes/named-class-expression.result.js create mode 100644 tests/fixtures/ecma-features/classes/named-class-expression.src.js create mode 100644 tests/fixtures/ecma-features/classes/named-derived-class-expression.result.js create mode 100644 tests/fixtures/ecma-features/classes/named-derived-class-expression.src.js create mode 100644 tests/fixtures/ecma-features/classes/super-function-call-in-object-literal.result.js create mode 100644 tests/fixtures/ecma-features/classes/super-function-call-in-object-literal.src.js create mode 100644 tests/fixtures/ecma-features/classes/super-function-call.result.js create mode 100644 tests/fixtures/ecma-features/classes/super-function-call.src.js create mode 100644 tests/fixtures/ecma-features/classes/super-property-call-in-object-literal.result.js create mode 100644 tests/fixtures/ecma-features/classes/super-property-call-in-object-literal.src.js create mode 100644 tests/fixtures/ecma-features/classes/super-property-call.result.js create mode 100644 tests/fixtures/ecma-features/classes/super-property-call.src.js diff --git a/README.md b/README.md index 9e08e527..28693ce3 100644 --- a/README.md +++ b/README.md @@ -110,9 +110,12 @@ var ast = espree.parse(code, { // enable parsing of generators/yield generators: true, - // support the spread operator + // enable parsing spread operator spread: true, + // enable parsing classes + classes: true, + // enable React JSX parsing jsx: true, diff --git a/espree.js b/espree.js index c5b08649..f5eb121d 100644 --- a/espree.js +++ b/espree.js @@ -2370,14 +2370,13 @@ function parseArrayInitialiser() { // 11.1.5 Object Initialiser -function parsePropertyFunction(options) { +function parsePropertyFunction(paramInfo, options) { var previousStrict = strict, previousYieldAllowed = state.yieldAllowed, - params = options.params || [], - defaults = options.defaults || [], + generator = options ? options.generator : false, body; - state.yieldAllowed = options.generator; + state.yieldAllowed = generator; /* * Esprima uses parseConciseBody() here, which is incorrect. Object literal @@ -2385,8 +2384,12 @@ function parsePropertyFunction(options) { */ body = parseFunctionSourceElements(); - if (options.name && strict && syntax.isRestrictedWord(params[0].name)) { - throwErrorTolerant(options.name, Messages.StrictParamName); + if (strict && paramInfo.firstRestricted) { + throwErrorTolerant(paramInfo.firstRestricted, Messages.StrictParamName); + } + + if (strict && paramInfo.stricted) { + throwErrorTolerant(paramInfo.stricted, paramInfo.message); } strict = previousStrict; @@ -2394,11 +2397,11 @@ function parsePropertyFunction(options) { return markerApply(options.marker, astNodeFactory.createFunctionExpression( null, - params, - defaults, + paramInfo.params, + paramInfo.defaults, body, - options.rest || null, - options.generator, + paramInfo.rest, + generator, body.type !== astNodeTypes.BlockStatement )); } @@ -2406,21 +2409,18 @@ function parsePropertyFunction(options) { function parsePropertyMethodFunction(options) { var previousStrict = strict, marker = markerCreate(), - tmp, + params, method; strict = true; - tmp = parseParams(); + params = parseParams(); - if (tmp.stricted) { - throwErrorTolerant(tmp.stricted, tmp.message); + if (params.stricted) { + throwErrorTolerant(params.stricted, params.message); } - method = parsePropertyFunction({ - params: tmp.params, - defaults: tmp.defaults, - rest: tmp.rest, + method = parsePropertyFunction(params, { generator: options ? options.generator : false, marker: marker }); @@ -2433,34 +2433,133 @@ function parsePropertyMethodFunction(options) { function parseObjectPropertyKey() { var marker = markerCreate(), token = lex(), - propertyKey, + allowObjectLiteralComputed = extra.ecmaFeatures.objectLiteralComputedProperties, + expr, result; // Note: This function is called only from parseObjectProperty(), where // EOF and Punctuator tokens are already filtered out. - if (token.type === Token.StringLiteral || token.type === Token.NumericLiteral) { - if (strict && token.octal) { - throwErrorTolerant(token, Messages.StrictOctalLiteral); + switch (token.type) { + case Token.StringLiteral: + case Token.NumericLiteral: + if (strict && token.octal) { + throwErrorTolerant(token, Messages.StrictOctalLiteral); + } + return markerApply(marker, astNodeFactory.createLiteralFromSource(token, source)); + + case Token.Identifier: + case Token.BooleanLiteral: + case Token.NullLiteral: + case Token.Keyword: + return markerApply(marker, astNodeFactory.createIdentifier(token.value)); + + case Token.Punctuator: + if ((!state.inObjectLiteral || allowObjectLiteralComputed) && + token.value === "[") { + // For computed properties we should skip the [ and ], and + // capture in marker only the assignment expression itself. + marker = markerCreate(); + expr = parseAssignmentExpression(); + result = markerApply(marker, expr); + expect("]"); + return result; + } + + // no default + } + + throwUnexpected(token); +} + +function lookaheadPropertyName() { + switch (lookahead.type) { + case Token.Identifier: + case Token.StringLiteral: + case Token.BooleanLiteral: + case Token.NullLiteral: + case Token.NumericLiteral: + case Token.Keyword: + return true; + case Token.Punctuator: + return lookahead.value === "["; + // no default + } + return false; +} + +// This function is to try to parse a MethodDefinition as defined in 14.3. But in the case of object literals, +// it might be called at a position where there is in fact a short hand identifier pattern or a data property. +// This can only be determined after we consumed up to the left parentheses. +// In order to avoid back tracking, it returns `null` if the position is not a MethodDefinition and the caller +// is responsible to visit other options. +function tryParseMethodDefinition(token, key, computed, marker) { + var value, options, methodMarker; + + if (token.type === Token.Identifier) { + // check for `get` and `set`; + + if (token.value === "get" && lookaheadPropertyName()) { + + computed = match("["); + key = parseObjectPropertyKey(); + methodMarker = markerCreate(); + expect("("); + expect(")"); + + value = parsePropertyFunction({ + params: [], + defaults: [], + stricted: null, + firstRestricted: null, + message: null, + rest: null + }, { + marker: methodMarker + }); + + return markerApply(marker, astNodeFactory.createProperty("get", key, value, false, false, computed)); + + } else if (token.value === "set" && lookaheadPropertyName()) { + computed = match("["); + key = parseObjectPropertyKey(); + methodMarker = markerCreate(); + expect("("); + + options = { + params: [], + defaultCount: 0, + defaults: [], + stricted: null, + firstRestricted: null, + paramSet: new StringMap(), + rest: null + }; + if (match(")")) { + throwErrorTolerant(lookahead, Messages.UnexpectedToken); + } else { + parseParam(options); + if (options.defaultCount === 0) { + options.defaults = []; + } + } + expect(")"); + + value = parsePropertyFunction(options, { marker: methodMarker }); + return markerApply(marker, astNodeFactory.createProperty("set", key, value, false, false, computed)); } - return markerApply(marker, astNodeFactory.createLiteralFromSource(token, source)); } - if (extra.ecmaFeatures.objectLiteralComputedProperties && - token.type === Token.Punctuator && token.value === "[" - ) { - // For computed properties we should skip the [ and ], and - // capture in marker only the assignment expression itself. - marker = markerCreate(); - propertyKey = parseAssignmentExpression(); - result = markerApply(marker, propertyKey); - expect("]"); - return result; + if (match("(")) { + value = parsePropertyMethodFunction(); + return markerApply(marker, astNodeFactory.createProperty("init", key, value, true, false, computed)); } - return markerApply(marker, astNodeFactory.createIdentifier(token.value)); + // Not a MethodDefinition. + return null; } + function parseObjectProperty() { var token, key, id, param, computed, methodMarker; var allowComputed = extra.ecmaFeatures.objectLiteralComputedProperties, @@ -2487,13 +2586,15 @@ function parseObjectProperty() { methodMarker = markerCreate(); expect("("); expect(")"); + return markerApply( marker, astNodeFactory.createProperty( "get", key, parsePropertyFunction({ - generator: false, + generator: false + }, { marker: methodMarker }), false, @@ -2519,7 +2620,8 @@ function parseObjectProperty() { parsePropertyFunction({ params: param, generator: false, - name: token, + name: token + }, { marker: methodMarker }), false, @@ -2674,6 +2776,8 @@ function parseObjectInitialiser() { storedKind, kindMap = new StringMap(); + state.inObjectLiteral = true; + expect("{"); while (!match("}")) { @@ -2720,6 +2824,8 @@ function parseObjectInitialiser() { expect("}"); + state.inObjectLiteral = false; + return markerApply(marker, astNodeFactory.createObjectExpression(properties)); } @@ -2784,7 +2890,8 @@ function parsePrimaryExpression() { var type, token, expr, marker, allowJSX = extra.ecmaFeatures.jsx, - allowSuper = extra.ecmaFeatures.superInFunctions; + allowSuper = extra.ecmaFeatures.superInFunctions, + allowClasses = extra.ecmaFeatures.classes; if (match("(")) { return parseGroupExpression(); @@ -2824,11 +2931,16 @@ function parsePrimaryExpression() { } if (matchKeyword("this")) { + marker = markerCreate(); lex(); - expr = astNodeFactory.createThisExpression(); - } else { - throwUnexpected(lex()); + return markerApply(marker, astNodeFactory.createThisExpression()); + } + + if (allowClasses && matchKeyword("class")) { + return parseClassExpression(); } + + throwUnexpected(lex()); } else if (type === Token.BooleanLiteral) { token = lex(); token.value = (token.value === "true"); @@ -4245,6 +4357,7 @@ function parseFunctionSourceElements() { directive = source.slice(token.range[0] + 1, token.range[1] - 1); if (directive === "use strict") { strict = true; + if (firstRestricted) { throwErrorTolerant(firstRestricted, Messages.StrictOctalLiteral); } @@ -4293,11 +4406,13 @@ function parseFunctionSourceElements() { } function validateParam(options, param, name) { + if (strict) { if (syntax.isRestrictedWord(name)) { options.stricted = param; options.message = Messages.StrictParamName; } + if (options.paramSet.has(name)) { options.stricted = param; options.message = Messages.StrictParamDupe; @@ -4323,6 +4438,7 @@ function parseParam(options) { allowDestructuring = extra.ecmaFeatures.destructuring, allowDefaultParams = extra.ecmaFeatures.defaultParams; + token = lookahead; if (token.value === "...") { if (!allowRestParams) { @@ -4380,7 +4496,7 @@ function parseParam(options) { function parseParams(firstRestricted) { - var options, marker = markerCreate(); + var options; options = { params: [], @@ -4408,7 +4524,14 @@ function parseParams(firstRestricted) { options.defaults = []; } - return markerApply(marker, options); + return { + params: options.params, + defaults: options.defaults, + rest: options.rest, + stricted: options.stricted, + firstRestricted: options.firstRestricted, + message: options.message + }; } function parseFunctionDeclaration() { @@ -4565,14 +4688,149 @@ function parseYieldExpression() { return markerApply(marker, astNodeFactory.createYieldExpression(expr, delegateFlag)); } +// 14 Functions and classes + +// 14.1 Functions is defined above (13 in ES5) +// 14.2 Arrow Functions Definitions is defined in (7.3 assignments) + +// 14.3 Method Definitions +// 14.3.7 + +// 14.5 Class Definitions + +function parseClassBody() { + var token, isStatic, hasConstructor = false, body = [], method, computed, key; + + var existingProps = {}, + topMarker = markerCreate(), + marker; + + existingProps.static = new StringMap(); + existingProps.prototype = new StringMap(); + + expect("{"); + + while (!match("}")) { + + // extra semicolons are fine + if (match(";")) { + lex(); + continue; + } + + token = lookahead; + isStatic = false; + computed = match("["); + marker = markerCreate(); + key = parseObjectPropertyKey(); + + if (key.name === "static" && lookaheadPropertyName()) { + token = lookahead; + isStatic = true; + computed = match("["); + key = parseObjectPropertyKey(); + console.dir(key); + } + + method = tryParseMethodDefinition(token, key, computed, marker); + + if (method) { + method.static = isStatic; + if (method.kind === "init") { + method.kind = "method"; + } + + if (!isStatic) { + if (!method.computed && (method.key.name || method.key.value.toString()) === "constructor") { + if (method.kind !== "method" || !method.method || method.value.generator) { + throwUnexpected(token, Messages.ConstructorSpecialMethod); + } + if (hasConstructor) { + throwUnexpected(token, Messages.DuplicateConstructor); + } else { + hasConstructor = true; + } + method.kind = "constructor"; + } + } else { + if (!method.computed && (method.key.name || method.key.value.toString()) === "prototype") { + throwUnexpected(token, Messages.StaticPrototype); + } + } + method.type = astNodeTypes.MethodDefinition; + delete method.method; + delete method.shorthand; + body.push(method); + } else { + throwUnexpected(lookahead); + } + } + + lex(); + return markerApply(topMarker, astNodeFactory.createClassBody(body)); +} + +function parseClassExpression() { + var id = null, superClass = null, marker = markerCreate(), + previousStrict = strict, classBody; + + // classes run in strict mode + strict = true; + + expectKeyword("class"); + + if (lookahead.type === Token.Identifier) { + id = parseVariableIdentifier(); + } + + if (matchKeyword("extends")) { + lex(); + superClass = parseLeftHandSideExpressionAllowCall(); + } + + classBody = parseClassBody(); + strict = previousStrict; + + return markerApply(marker, astNodeFactory.createClassExpression(id, superClass, classBody)); +} + +function parseClassDeclaration() { + var id, superClass = null, marker = markerCreate(), + previousStrict = strict, classBody; + + // classes run in strict mode + strict = true; + + expectKeyword("class"); + + id = parseVariableIdentifier(); + + if (matchKeyword("extends")) { + lex(); + superClass = parseLeftHandSideExpressionAllowCall(); + } + + classBody = parseClassBody(); + strict = previousStrict; + + return markerApply(marker, astNodeFactory.createClassDeclaration(id, superClass, classBody)); +} -// 14 Program +// 15 Program function parseSourceElement() { + + var allowClasses = extra.ecmaFeatures.classes; + if (lookahead.type === Token.Keyword) { switch (lookahead.value) { case "function": return parseFunctionDeclaration(); + case "class": + if (allowClasses) { + return parseClassDeclaration(); + } + break; case "const": case "let": if (extra.ecmaFeatures.blockBindings) { diff --git a/lib/ast-node-factory.js b/lib/ast-node-factory.js index 06b6930a..f8f3f90b 100644 --- a/lib/ast-node-factory.js +++ b/lib/ast-node-factory.js @@ -161,6 +161,47 @@ module.exports = { }; }, + /** + * Creates an ASTNode representation of a class body. + * @param {ASTNode} body The node representing the body of the class. + * @returns {ASTNode} An ASTNode representing the class body. + */ + createClassBody: function (body) { + return { + type: astNodeTypes.ClassBody, + body: body + }; + }, + + createClassExpression: function (name, superClass, body) { + return { + type: astNodeTypes.ClassExpression, + name: name, + superClass: superClass, + body: body + }; + }, + + createClassDeclaration: function (name, superClass, body) { + return { + type: astNodeTypes.ClassDeclaration, + name: name, + superClass: superClass, + body: body + }; + }, + + createMethodDefinition: function (propertyType, kind, key, value, computed) { + return { + type: astNodeTypes.MethodDefinition, + key: key, + value: value, + kind: kind, + "static": propertyType === "static", + computed: computed + }; + }, + /** * Create an ASTNode representation of a conditional expression * @param {ASTNode} test The conditional to evaluate @@ -317,7 +358,7 @@ module.exports = { return { type: astNodeTypes.FunctionDeclaration, id: id, - params: params, + params: params || [], defaults: defaults || [], body: body, rest: rest || null, @@ -341,7 +382,7 @@ module.exports = { return { type: astNodeTypes.FunctionExpression, id: id, - params: params, + params: params || [], defaults: defaults || [], body: body, rest: rest || null, diff --git a/lib/ast-node-types.js b/lib/ast-node-types.js index 58fc3452..e52ddec0 100644 --- a/lib/ast-node-types.js +++ b/lib/ast-node-types.js @@ -47,6 +47,9 @@ module.exports = { BreakStatement: "BreakStatement", CallExpression: "CallExpression", CatchClause: "CatchClause", + ClassBody: "ClassBody", + ClassDeclaration: "ClassDeclaration", + ClassExpression: "ClassExpression", ConditionalExpression: "ConditionalExpression", ContinueStatement: "ContinueStatement", DoWhileStatement: "DoWhileStatement", @@ -64,6 +67,7 @@ module.exports = { LabeledStatement: "LabeledStatement", LogicalExpression: "LogicalExpression", MemberExpression: "MemberExpression", + MethodDefinition: "MethodDefinition", NewExpression: "NewExpression", ObjectExpression: "ObjectExpression", ObjectPattern: "ObjectPattern", diff --git a/lib/features.js b/lib/features.js index 3c2b17c3..cc0be826 100644 --- a/lib/features.js +++ b/lib/features.js @@ -97,6 +97,9 @@ module.exports = { // enable super in functions superInFunctions: false, + // enable parsing of classes + classes: false, + // React JSX parsing jsx: false, diff --git a/lib/messages.js b/lib/messages.js index 0d817391..41651c8f 100644 --- a/lib/messages.js +++ b/lib/messages.js @@ -78,6 +78,9 @@ module.exports = { StrictDelete: "Delete of an unqualified identifier in strict mode.", StrictDuplicateProperty: "Duplicate data property in object literal not allowed in strict mode", DuplicatePrototypeProperty: "Duplicate '__proto__' property in object literal are not allowed", + ConstructorSpecialMethod: "Class constructor may not be an accessor", + DuplicateConstructor: "A class may only have one constructor", + StaticPrototype: "Classes may not have static property named prototype", AccessorDataProperty: "Object literal may not have data and accessor property with the same name", AccessorGetSet: "Object literal may not have multiple get/set accessors with the same name", StrictLHSAssignment: "Assignment to eval or arguments is not allowed in strict mode", diff --git a/test/3rdparty/syntax/README b/test/3rdparty/syntax/README deleted file mode 100644 index 5374c487..00000000 --- a/test/3rdparty/syntax/README +++ /dev/null @@ -1 +0,0 @@ -This directory holds the syntax tree of every tested library. diff --git a/tests/fixtures/ast/API.json b/tests/fixtures/ast/API.json deleted file mode 100644 index b9aa8afa..00000000 --- a/tests/fixtures/ast/API.json +++ /dev/null @@ -1,308 +0,0 @@ -{ - "parse()": { - "call": "parse", - "args": [], - "result": { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "Identifier", - "name": "undefined" - } - } - ] - } - }, - "parse(null)": { - "call": "parse", - "args": [ - null - ], - "result": { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "Literal", - "value": null, - "raw": "null" - } - } - ] - } - }, - "parse(42)": { - "call": "parse", - "args": [ - 42 - ], - "result": { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "Literal", - "value": 42, - "raw": "42" - } - } - ] - } - }, - "parse(true)": { - "call": "parse", - "args": [ - true - ], - "result": { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "Literal", - "value": true, - "raw": "true" - } - } - ] - } - }, - "parse(undefined)": { - "call": "parse", - "args": [ - "espree@undefined" - ], - "result": { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "Identifier", - "name": "undefined" - } - } - ] - } - }, - "parse(new String(\"test\"))": { - "call": "parse", - "args": [ - "test" - ], - "result": { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "Identifier", - "name": "test" - } - } - ] - } - }, - "parse(new Number(42))": { - "call": "parse", - "args": [ - 42 - ], - "result": { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "Literal", - "value": 42, - "raw": "42" - } - } - ] - } - }, - "parse(new Boolean(true))": { - "call": "parse", - "args": [ - true - ], - "result": { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "Literal", - "value": true, - "raw": "true" - } - } - ] - } - }, - "Syntax": { - "property": "Syntax", - "result": { - "AssignmentExpression": "AssignmentExpression", - "ArrayExpression": "ArrayExpression", - "ArrayPattern": "ArrayPattern", - "ArrowFunctionExpression": "ArrowFunctionExpression", - "BlockStatement": "BlockStatement", - "BinaryExpression": "BinaryExpression", - "BreakStatement": "BreakStatement", - "CallExpression": "CallExpression", - "CatchClause": "CatchClause", - "ConditionalExpression": "ConditionalExpression", - "ContinueStatement": "ContinueStatement", - "DoWhileStatement": "DoWhileStatement", - "DebuggerStatement": "DebuggerStatement", - "EmptyStatement": "EmptyStatement", - "ExpressionStatement": "ExpressionStatement", - "ForStatement": "ForStatement", - "ForInStatement": "ForInStatement", - "ForOfStatement": "ForOfStatement", - "FunctionDeclaration": "FunctionDeclaration", - "FunctionExpression": "FunctionExpression", - "Identifier": "Identifier", - "IfStatement": "IfStatement", - "Literal": "Literal", - "LabeledStatement": "LabeledStatement", - "LogicalExpression": "LogicalExpression", - "MemberExpression": "MemberExpression", - "NewExpression": "NewExpression", - "ObjectExpression": "ObjectExpression", - "ObjectPattern": "ObjectPattern", - "Program": "Program", - "Property": "Property", - "ReturnStatement": "ReturnStatement", - "SequenceExpression": "SequenceExpression", - "SpreadElement": "SpreadElement", - "SwitchCase": "SwitchCase", - "SwitchStatement": "SwitchStatement", - "TaggedTemplateExpression": "TaggedTemplateExpression", - "TemplateElement": "TemplateElement", - "TemplateLiteral": "TemplateLiteral", - "ThisExpression": "ThisExpression", - "ThrowStatement": "ThrowStatement", - "TryStatement": "TryStatement", - "UnaryExpression": "UnaryExpression", - "UpdateExpression": "UpdateExpression", - "VariableDeclaration": "VariableDeclaration", - "VariableDeclarator": "VariableDeclarator", - "WhileStatement": "WhileStatement", - "WithStatement": "WithStatement", - "YieldExpression": "YieldExpression", - "JSXIdentifier": "JSXIdentifier", - "JSXNamespacedName": "JSXNamespacedName", - "JSXMemberExpression": "JSXMemberExpression", - "JSXEmptyExpression": "JSXEmptyExpression", - "JSXExpressionContainer": "JSXExpressionContainer", - "JSXElement": "JSXElement", - "JSXClosingElement": "JSXClosingElement", - "JSXOpeningElement": "JSXOpeningElement", - "JSXAttribute": "JSXAttribute", - "JSXSpreadAttribute": "JSXSpreadAttribute", - "JSXText": "JSXText" - } - }, - "tokenize()": { - "call": "tokenize", - "args": [], - "result": [ - { - "type": "Identifier", - "value": "undefined" - } - ] - }, - "tokenize(null)": { - "call": "tokenize", - "args": [ - null - ], - "result": [ - { - "type": "Null", - "value": "null" - } - ] - }, - "tokenize(42)": { - "call": "tokenize", - "args": [ - 42 - ], - "result": [ - { - "type": "Numeric", - "value": "42" - } - ] - }, - "tokenize(true)": { - "call": "tokenize", - "args": [ - true - ], - "result": [ - { - "type": "Boolean", - "value": "true" - } - ] - }, - "tokenize(undefined)": { - "call": "tokenize", - "args": [ - "espree@undefined" - ], - "result": [ - { - "type": "Identifier", - "value": "undefined" - } - ] - }, - "tokenize(new String(\"test\"))": { - "call": "tokenize", - "args": [ - "test" - ], - "result": [ - { - "type": "Identifier", - "value": "test" - } - ] - }, - "tokenize(new Number(42))": { - "call": "tokenize", - "args": [ - 42 - ], - "result": [ - { - "type": "Numeric", - "value": "42" - } - ] - }, - "tokenize(new Boolean(true))": { - "call": "tokenize", - "args": [ - true - ], - "result": [ - { - "type": "Boolean", - "value": "true" - } - ] - } -} diff --git a/tests/fixtures/ecma-features/classes/class-accessor-properties.result.js b/tests/fixtures/ecma-features/classes/class-accessor-properties.result.js new file mode 100644 index 00000000..1aeb3888 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-accessor-properties.result.js @@ -0,0 +1,268 @@ +module.exports = { + "range": [ + 0, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": false, + "value": { + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 16, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "get", + "static": false + }, + { + "range": [ + 19, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "type": "Identifier", + "name": "b" + }, + "computed": false, + "value": { + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [ + { + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "Identifier", + "name": "c" + } + ], + "defaults": [], + "body": { + "range": [ + 27, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "set", + "static": false + } + ] + } + }, + { + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-accessor-properties.src.js b/tests/fixtures/ecma-features/classes/class-accessor-properties.src.js new file mode 100644 index 00000000..5788395a --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-accessor-properties.src.js @@ -0,0 +1 @@ +class A {get a(){} set b(c){};}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-computed-static-method.result.js b/tests/fixtures/ecma-features/classes/class-computed-static-method.result.js new file mode 100644 index 00000000..77d32eea --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-computed-static-method.result.js @@ -0,0 +1,170 @@ +module.exports = { + "range": [ + 0, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": true, + "value": { + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 21, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": true + } + ] + } + }, + { + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-computed-static-method.src.js b/tests/fixtures/ecma-features/classes/class-computed-static-method.src.js new file mode 100644 index 00000000..f960fe06 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-computed-static-method.src.js @@ -0,0 +1 @@ +class A {static [a](){};}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-expression.result.js b/tests/fixtures/ecma-features/classes/class-expression.result.js new file mode 100644 index 00000000..0c20d274 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-expression.result.js @@ -0,0 +1,73 @@ +module.exports = { + "range": [ + 0, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "ExpressionStatement", + "expression": { + "range": [ + 1, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "type": "ClassExpression", + "name": null, + "superClass": null, + "body": { + "range": [ + 7, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "type": "ClassBody", + "body": [] + } + } + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-expression.src.js b/tests/fixtures/ecma-features/classes/class-expression.src.js new file mode 100644 index 00000000..ac7ea1be --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-expression.src.js @@ -0,0 +1 @@ +(class {}); \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-method-named-prototype.result.js b/tests/fixtures/ecma-features/classes/class-method-named-prototype.result.js new file mode 100644 index 00000000..6f556fb8 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-method-named-prototype.result.js @@ -0,0 +1,170 @@ +module.exports = { + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 9, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "type": "Identifier", + "name": "prototype" + }, + "computed": false, + "value": { + "range": [ + 18, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 20, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + } + ] + } + }, + { + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-method-named-prototype.src.js b/tests/fixtures/ecma-features/classes/class-method-named-prototype.src.js new file mode 100644 index 00000000..5f8f86ae --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-method-named-prototype.src.js @@ -0,0 +1 @@ +class A {prototype(){}}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-method-named-static.result.js b/tests/fixtures/ecma-features/classes/class-method-named-static.result.js new file mode 100644 index 00000000..0d2e5b82 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-method-named-static.result.js @@ -0,0 +1,170 @@ +module.exports = { + "range": [ + 0, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 9, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "type": "Identifier", + "name": "static" + }, + "computed": false, + "value": { + "range": [ + 15, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 17, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + } + ] + } + }, + { + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-method-named-static.src.js b/tests/fixtures/ecma-features/classes/class-method-named-static.src.js new file mode 100644 index 00000000..4b8882f7 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-method-named-static.src.js @@ -0,0 +1 @@ +class A {static(){};}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-one-method.result.js b/tests/fixtures/ecma-features/classes/class-one-method.result.js new file mode 100644 index 00000000..25f32b5f --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-one-method.result.js @@ -0,0 +1,170 @@ +module.exports = { + "range": [ + 0, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 14, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": false, + "value": { + "range": [ + 15, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 17, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + } + ] + } + }, + { + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-one-method.src.js b/tests/fixtures/ecma-features/classes/class-one-method.src.js new file mode 100644 index 00000000..cbae5822 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-one-method.src.js @@ -0,0 +1,3 @@ +class A { + a(){} +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-static-method-named-prototype.result.js b/tests/fixtures/ecma-features/classes/class-static-method-named-prototype.result.js new file mode 100644 index 00000000..bda8cd87 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-static-method-named-prototype.result.js @@ -0,0 +1,171 @@ +module.exports = { + "range": [ + 0, + 35 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 17, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "type": "Literal", + "value": "prototype", + "raw": "\"prototype\"" + }, + "computed": true, + "value": { + "range": [ + 29, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 31, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": true + } + ] + } + }, + { + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-static-method-named-prototype.src.js b/tests/fixtures/ecma-features/classes/class-static-method-named-prototype.src.js new file mode 100644 index 00000000..9a2019e9 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-static-method-named-prototype.src.js @@ -0,0 +1 @@ +class A {static ["prototype"](){}}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-static-method-named-static.result.js b/tests/fixtures/ecma-features/classes/class-static-method-named-static.result.js new file mode 100644 index 00000000..e695e9c3 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-static-method-named-static.result.js @@ -0,0 +1,170 @@ +module.exports = { + "range": [ + 0, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 16, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "Identifier", + "name": "static" + }, + "computed": false, + "value": { + "range": [ + 22, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 24, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": true + } + ] + } + }, + { + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-static-method-named-static.src.js b/tests/fixtures/ecma-features/classes/class-static-method-named-static.src.js new file mode 100644 index 00000000..947d978d --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-static-method-named-static.src.js @@ -0,0 +1 @@ +class A {static static(){};}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-static-method.result.js b/tests/fixtures/ecma-features/classes/class-static-method.result.js new file mode 100644 index 00000000..d55b367d --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-static-method.result.js @@ -0,0 +1,170 @@ +module.exports = { + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": false, + "value": { + "range": [ + 17, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 19, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": true + } + ] + } + }, + { + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-static-method.src.js b/tests/fixtures/ecma-features/classes/class-static-method.src.js new file mode 100644 index 00000000..dea98b8d --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-static-method.src.js @@ -0,0 +1 @@ +class A {static a(){};}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.result.js b/tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.result.js new file mode 100644 index 00000000..3b730e4b --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.result.js @@ -0,0 +1,347 @@ +module.exports = { + "range": [ + 0, + 59 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 59 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 58 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 58 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 58 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 58 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": false, + "value": { + "range": [ + 17, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 19, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": true + }, + { + "range": [ + 22, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": false, + "value": { + "range": [ + 34, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 36, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "get", + "static": true + }, + { + "range": [ + 39, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 1, + "column": 50 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": false, + "value": { + "range": [ + 51, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 51 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [ + { + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 1, + "column": 52 + }, + "end": { + "line": 1, + "column": 53 + } + }, + "type": "Identifier", + "name": "b" + } + ], + "defaults": [], + "body": { + "range": [ + 54, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 54 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "set", + "static": true + } + ] + } + }, + { + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 1, + "column": 58 + }, + "end": { + "line": 1, + "column": 59 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.src.js b/tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.src.js new file mode 100644 index 00000000..5efab6d9 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-static-methods-and-accessor-properties.src.js @@ -0,0 +1 @@ +class A {static a(){} static get a(){} static set a(b){} }; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-computed-static-methods.result.js b/tests/fixtures/ecma-features/classes/class-two-computed-static-methods.result.js new file mode 100644 index 00000000..5341181a --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-computed-static-methods.result.js @@ -0,0 +1,249 @@ +module.exports = { + "range": [ + 0, + 39 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": true, + "value": { + "range": [ + 18, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 20, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": true + }, + { + "range": [ + 24, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "type": "Identifier", + "name": "b" + }, + "computed": true, + "value": { + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 35, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": true + } + ] + } + }, + { + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-computed-static-methods.src.js b/tests/fixtures/ecma-features/classes/class-two-computed-static-methods.src.js new file mode 100644 index 00000000..8a3d1cf9 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-computed-static-methods.src.js @@ -0,0 +1 @@ +class A {static[a](){}; static[b](){}}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.result.js b/tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.result.js new file mode 100644 index 00000000..9655e1da --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.result.js @@ -0,0 +1,251 @@ +module.exports = { + "range": [ + 0, + 48 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 47 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 47 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 9, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "Literal", + "value": "constructor", + "raw": "\"constructor\"" + }, + "computed": false, + "value": { + "range": [ + 22, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 24, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "constructor", + "static": false + }, + { + "range": [ + 27, + 46 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 28, + 41 + ], + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "type": "Literal", + "value": "constructor", + "raw": "\"constructor\"" + }, + "computed": true, + "value": { + "range": [ + 42, + 46 + ], + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 44, + 46 + ], + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + } + ] + } + }, + { + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 1, + "column": 47 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.src.js b/tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.src.js new file mode 100644 index 00000000..66a3500b --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-methods-computed-constructor.src.js @@ -0,0 +1 @@ +class A {"constructor"(){} ["constructor"](){}}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-semi.result.js b/tests/fixtures/ecma-features/classes/class-two-methods-semi.result.js new file mode 100644 index 00000000..5e5a6f91 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-methods-semi.result.js @@ -0,0 +1,249 @@ +module.exports = { + "range": [ + 0, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": false, + "value": { + "range": [ + 10, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 12, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + }, + { + "range": [ + 15, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "type": "Identifier", + "name": "b" + }, + "computed": false, + "value": { + "range": [ + 16, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 18, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + } + ] + } + }, + { + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-semi.src.js b/tests/fixtures/ecma-features/classes/class-two-methods-semi.src.js new file mode 100644 index 00000000..eae3cf56 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-methods-semi.src.js @@ -0,0 +1 @@ +class A {a(){};b(){}}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-three-semi.result.js b/tests/fixtures/ecma-features/classes/class-two-methods-three-semi.result.js new file mode 100644 index 00000000..b45a4059 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-methods-three-semi.result.js @@ -0,0 +1,249 @@ +module.exports = { + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": false, + "value": { + "range": [ + 11, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 13, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + }, + { + "range": [ + 16, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "type": "Identifier", + "name": "b" + }, + "computed": false, + "value": { + "range": [ + 17, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 19, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + } + ] + } + }, + { + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-three-semi.src.js b/tests/fixtures/ecma-features/classes/class-two-methods-three-semi.src.js new file mode 100644 index 00000000..db2c06ce --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-methods-three-semi.src.js @@ -0,0 +1 @@ +class A {;a(){};b(){};}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-two-semi.result.js b/tests/fixtures/ecma-features/classes/class-two-methods-two-semi.result.js new file mode 100644 index 00000000..998dfca3 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-methods-two-semi.result.js @@ -0,0 +1,249 @@ +module.exports = { + "range": [ + 0, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": false, + "value": { + "range": [ + 10, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 12, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + }, + { + "range": [ + 15, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "type": "Identifier", + "name": "b" + }, + "computed": false, + "value": { + "range": [ + 16, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 18, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + } + ] + } + }, + { + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-methods-two-semi.src.js b/tests/fixtures/ecma-features/classes/class-two-methods-two-semi.src.js new file mode 100644 index 00000000..30f2b72c --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-methods-two-semi.src.js @@ -0,0 +1 @@ +class A {a(){};b(){};}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-methods.result.js b/tests/fixtures/ecma-features/classes/class-two-methods.result.js new file mode 100644 index 00000000..019610f8 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-methods.result.js @@ -0,0 +1,249 @@ +module.exports = { + "range": [ + 0, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "type": "Identifier", + "name": "a" + }, + "computed": false, + "value": { + "range": [ + 10, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 12, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + }, + { + "range": [ + 14, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "type": "Identifier", + "name": "b" + }, + "computed": false, + "value": { + "range": [ + 15, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 17, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": false + } + ] + } + }, + { + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-methods.src.js b/tests/fixtures/ecma-features/classes/class-two-methods.src.js new file mode 100644 index 00000000..b30e1d96 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-methods.src.js @@ -0,0 +1 @@ +class A {a(){}b(){}}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-static-methods-named-constructor.result.js b/tests/fixtures/ecma-features/classes/class-two-static-methods-named-constructor.result.js new file mode 100644 index 00000000..f4b726d1 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-static-methods-named-constructor.result.js @@ -0,0 +1,249 @@ +module.exports = { + "range": [ + 0, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 55 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 55 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 55 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 55 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 16, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "type": "Identifier", + "name": "constructor" + }, + "computed": false, + "value": { + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 29, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": true + }, + { + "range": [ + 32, + 54 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 39, + 50 + ], + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "type": "Identifier", + "name": "constructor" + }, + "computed": false, + "value": { + "range": [ + 50, + 54 + ], + "loc": { + "start": { + "line": 1, + "column": 50 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 52, + 54 + ], + "loc": { + "start": { + "line": 1, + "column": 52 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "method", + "static": true + } + ] + } + }, + { + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 55 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-two-static-methods-named-constructor.src.js b/tests/fixtures/ecma-features/classes/class-two-static-methods-named-constructor.src.js new file mode 100644 index 00000000..57bbee9d --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-two-static-methods-named-constructor.src.js @@ -0,0 +1 @@ +class A {static constructor(){} static constructor(){}}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-with-constructor.result.js b/tests/fixtures/ecma-features/classes/class-with-constructor.result.js new file mode 100644 index 00000000..19222c37 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-with-constructor.result.js @@ -0,0 +1,170 @@ +module.exports = { + "range": [ + 0, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "type": "ClassBody", + "body": [ + { + "range": [ + 9, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "type": "MethodDefinition", + "key": { + "range": [ + 9, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "Identifier", + "name": "constructor" + }, + "computed": false, + "value": { + "range": [ + 20, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "range": [ + 22, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "type": "BlockStatement", + "body": [] + }, + "rest": null, + "generator": false, + "expression": false + }, + "kind": "constructor", + "static": false + } + ] + } + }, + { + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/class-with-constructor.src.js b/tests/fixtures/ecma-features/classes/class-with-constructor.src.js new file mode 100644 index 00000000..00fcd7be --- /dev/null +++ b/tests/fixtures/ecma-features/classes/class-with-constructor.src.js @@ -0,0 +1 @@ +class A {constructor(){}}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/derived-class-assign-to-var.result.js b/tests/fixtures/ecma-features/classes/derived-class-assign-to-var.result.js new file mode 100644 index 00000000..573682a8 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/derived-class-assign-to-var.result.js @@ -0,0 +1,146 @@ +module.exports = { + "range": [ + 0, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "type": "VariableDeclaration", + "declarations": [ + { + "range": [ + 4, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "type": "VariableDeclarator", + "id": { + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "type": "Identifier", + "name": "x" + }, + "init": { + "range": [ + 8, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "type": "ClassExpression", + "name": { + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": { + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "type": "Literal", + "value": 0, + "raw": "0" + }, + "body": { + "range": [ + 25, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "type": "ClassBody", + "body": [] + } + } + } + ], + "kind": "var" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/derived-class-assign-to-var.src.js b/tests/fixtures/ecma-features/classes/derived-class-assign-to-var.src.js new file mode 100644 index 00000000..fba446ff --- /dev/null +++ b/tests/fixtures/ecma-features/classes/derived-class-assign-to-var.src.js @@ -0,0 +1 @@ +var x = class A extends 0{}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/derived-class-expression.result.js b/tests/fixtures/ecma-features/classes/derived-class-expression.result.js new file mode 100644 index 00000000..ea65055e --- /dev/null +++ b/tests/fixtures/ecma-features/classes/derived-class-expression.result.js @@ -0,0 +1,91 @@ +module.exports = { + "range": [ + 0, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "ExpressionStatement", + "expression": { + "range": [ + 1, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "type": "ClassExpression", + "name": null, + "superClass": { + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "type": "Literal", + "value": 0, + "raw": "0" + }, + "body": { + "range": [ + 16, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "type": "ClassBody", + "body": [] + } + } + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/derived-class-expression.src.js b/tests/fixtures/ecma-features/classes/derived-class-expression.src.js new file mode 100644 index 00000000..b5e6e62e --- /dev/null +++ b/tests/fixtures/ecma-features/classes/derived-class-expression.src.js @@ -0,0 +1 @@ +(class extends 0{}); \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/empty-class-double-semi.result.js b/tests/fixtures/ecma-features/classes/empty-class-double-semi.result.js new file mode 100644 index 00000000..f81cdde6 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/empty-class-double-semi.result.js @@ -0,0 +1,90 @@ +module.exports = { + "range": [ + 0, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "type": "ClassBody", + "body": [] + } + }, + { + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/empty-class-double-semi.src.js b/tests/fixtures/ecma-features/classes/empty-class-double-semi.src.js new file mode 100644 index 00000000..a650fd68 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/empty-class-double-semi.src.js @@ -0,0 +1 @@ +class A {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/empty-class-semi.result.js b/tests/fixtures/ecma-features/classes/empty-class-semi.result.js new file mode 100644 index 00000000..aa7ec455 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/empty-class-semi.result.js @@ -0,0 +1,90 @@ +module.exports = { + "range": [ + 0, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "ClassBody", + "body": [] + } + }, + { + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/empty-class-semi.src.js b/tests/fixtures/ecma-features/classes/empty-class-semi.src.js new file mode 100644 index 00000000..e14455cb --- /dev/null +++ b/tests/fixtures/ecma-features/classes/empty-class-semi.src.js @@ -0,0 +1 @@ +class A {;}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/empty-class.result.js b/tests/fixtures/ecma-features/classes/empty-class.result.js new file mode 100644 index 00000000..f81cdde6 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/empty-class.result.js @@ -0,0 +1,90 @@ +module.exports = { + "range": [ + 0, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 8, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "type": "ClassBody", + "body": [] + } + }, + { + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/empty-class.src.js b/tests/fixtures/ecma-features/classes/empty-class.src.js new file mode 100644 index 00000000..a650fd68 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/empty-class.src.js @@ -0,0 +1 @@ +class A {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/empty-literal-derived-class.result.js b/tests/fixtures/ecma-features/classes/empty-literal-derived-class.result.js new file mode 100644 index 00000000..dd492953 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/empty-literal-derived-class.result.js @@ -0,0 +1,108 @@ +module.exports = { + "range": [ + 0, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "ClassDeclaration", + "name": { + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": { + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "type": "Literal", + "value": 0, + "raw": "0" + }, + "body": { + "range": [ + 18, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "ClassBody", + "body": [] + } + }, + { + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "type": "EmptyStatement" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/empty-literal-derived-class.src.js b/tests/fixtures/ecma-features/classes/empty-literal-derived-class.src.js new file mode 100644 index 00000000..5903f34f --- /dev/null +++ b/tests/fixtures/ecma-features/classes/empty-literal-derived-class.src.js @@ -0,0 +1 @@ +class A extends 0 {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/invalid-super-global-call.result.js b/tests/fixtures/ecma-features/classes/invalid-super-global-call.result.js new file mode 100644 index 00000000..67bab5d4 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/invalid-super-global-call.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 0, + "lineNumber": 1, + "column": 1, + "description": "Unexpected reserved word" +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/invalid-super-global-call.src.js b/tests/fixtures/ecma-features/classes/invalid-super-global-call.src.js new file mode 100644 index 00000000..1cadceec --- /dev/null +++ b/tests/fixtures/ecma-features/classes/invalid-super-global-call.src.js @@ -0,0 +1 @@ +super(); \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/named-class-expression.result.js b/tests/fixtures/ecma-features/classes/named-class-expression.result.js new file mode 100644 index 00000000..ad31ec8d --- /dev/null +++ b/tests/fixtures/ecma-features/classes/named-class-expression.result.js @@ -0,0 +1,90 @@ +module.exports = { + "range": [ + 0, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "type": "ExpressionStatement", + "expression": { + "range": [ + 1, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "ClassExpression", + "name": { + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": null, + "body": { + "range": [ + 9, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "type": "ClassBody", + "body": [] + } + } + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/named-class-expression.src.js b/tests/fixtures/ecma-features/classes/named-class-expression.src.js new file mode 100644 index 00000000..9829e5d0 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/named-class-expression.src.js @@ -0,0 +1 @@ +(class A {}); \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/named-derived-class-expression.result.js b/tests/fixtures/ecma-features/classes/named-derived-class-expression.result.js new file mode 100644 index 00000000..4b251e61 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/named-derived-class-expression.result.js @@ -0,0 +1,108 @@ +module.exports = { + "range": [ + 0, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "Program", + "body": [ + { + "range": [ + 0, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "type": "ExpressionStatement", + "expression": { + "range": [ + 1, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "ClassExpression", + "name": { + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "type": "Identifier", + "name": "A" + }, + "superClass": { + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "type": "Literal", + "value": 0, + "raw": "0" + }, + "body": { + "range": [ + 18, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "type": "ClassBody", + "body": [] + } + } + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/named-derived-class-expression.src.js b/tests/fixtures/ecma-features/classes/named-derived-class-expression.src.js new file mode 100644 index 00000000..cb8f8a94 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/named-derived-class-expression.src.js @@ -0,0 +1 @@ +(class A extends 0{}); \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/super-function-call-in-object-literal.result.js b/tests/fixtures/ecma-features/classes/super-function-call-in-object-literal.result.js new file mode 100644 index 00000000..92b250be --- /dev/null +++ b/tests/fixtures/ecma-features/classes/super-function-call-in-object-literal.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 41, + "lineNumber": 4, + "column": 9, + "description": "Unexpected reserved word" +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/super-function-call-in-object-literal.src.js b/tests/fixtures/ecma-features/classes/super-function-call-in-object-literal.src.js new file mode 100644 index 00000000..730aa7fd --- /dev/null +++ b/tests/fixtures/ecma-features/classes/super-function-call-in-object-literal.src.js @@ -0,0 +1,6 @@ +var o = { + + foo: function() { + super(); + } +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/super-function-call.result.js b/tests/fixtures/ecma-features/classes/super-function-call.result.js new file mode 100644 index 00000000..45ceb0a9 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/super-function-call.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 21, + "lineNumber": 2, + "column": 5, + "description": "Unexpected reserved word" +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/super-function-call.src.js b/tests/fixtures/ecma-features/classes/super-function-call.src.js new file mode 100644 index 00000000..7937758a --- /dev/null +++ b/tests/fixtures/ecma-features/classes/super-function-call.src.js @@ -0,0 +1,3 @@ +function foo() { + super(); +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/super-property-call-in-object-literal.result.js b/tests/fixtures/ecma-features/classes/super-property-call-in-object-literal.result.js new file mode 100644 index 00000000..92b250be --- /dev/null +++ b/tests/fixtures/ecma-features/classes/super-property-call-in-object-literal.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 41, + "lineNumber": 4, + "column": 9, + "description": "Unexpected reserved word" +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/super-property-call-in-object-literal.src.js b/tests/fixtures/ecma-features/classes/super-property-call-in-object-literal.src.js new file mode 100644 index 00000000..babe3fee --- /dev/null +++ b/tests/fixtures/ecma-features/classes/super-property-call-in-object-literal.src.js @@ -0,0 +1,6 @@ +var o = { + + foo: function() { + super.foo(); + } +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/super-property-call.result.js b/tests/fixtures/ecma-features/classes/super-property-call.result.js new file mode 100644 index 00000000..45ceb0a9 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/super-property-call.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 21, + "lineNumber": 2, + "column": 5, + "description": "Unexpected reserved word" +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/classes/super-property-call.src.js b/tests/fixtures/ecma-features/classes/super-property-call.src.js new file mode 100644 index 00000000..eb670388 --- /dev/null +++ b/tests/fixtures/ecma-features/classes/super-property-call.src.js @@ -0,0 +1,3 @@ +function foo() { + super.foo(); +}; \ No newline at end of file diff --git a/tests/lib/ecma-features.js b/tests/lib/ecma-features.js index e653fcb0..43651913 100644 --- a/tests/lib/ecma-features.js +++ b/tests/lib/ecma-features.js @@ -84,14 +84,18 @@ describe("ecmaFeatures", function() { // if the result is an error, create an error object so deepEqual works if (expected.message || expected.description) { + var expectedError = new Error(expected.message || expected.description); Object.keys(expected).forEach(function(key) { expectedError[key] = expected[key]; }); expected = expectedError; + } else { + throw ex; } result = ex; // if an error is thrown, match the error + } assert.deepEqual(result, expected); });