diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index ae60b1746ba7..c94bd6da451d 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -2021,11 +2021,15 @@ export default class ExpressionParser extends LValParser { return this.createIdentifier(node, name); } - createIdentifier(node: N.Identifier, name: string): N.Identifier { + createIdentifier( + node: T, + name: string, + type: $PropertyType = "Identifier", + ): T { node.name = name; node.loc.identifierName = name; - return this.finishNode(node, "Identifier"); + return this.finishNode(node, type); } parseIdentifierName(pos: number, liberal?: boolean): string { diff --git a/packages/babel-parser/src/parser/lval.js b/packages/babel-parser/src/parser/lval.js index b4281ab2ffb7..de8d822a691f 100644 --- a/packages/babel-parser/src/parser/lval.js +++ b/packages/babel-parser/src/parser/lval.js @@ -369,6 +369,9 @@ export default class LValParser extends NodeUtils { "'let' is not allowed to be used as a name in 'let' or 'const' declarations.", ); } + /* falls through */ + + case "DecoratorIdentifier": if (!(bindingType & BIND_NONE)) { this.scope.declareName(expr.name, bindingType, expr.start); } diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 3e950d26578b..589a8052edd5 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -12,6 +12,7 @@ import { lineBreak, skipWhiteSpace } from "../util/whitespace"; import * as charCodes from "charcodes"; import { BIND_CLASS, + BIND_DECORATOR, BIND_LEXICAL, BIND_VAR, BIND_FUNCTION, @@ -105,10 +106,7 @@ export default class StatementParser extends ExpressionParser { if (!this.isContextual("let")) { return false; } - skipWhiteSpace.lastIndex = this.state.pos; - const skip = skipWhiteSpace.exec(this.input); - // $FlowIgnore - const next = this.state.pos + skip[0].length; + const next = this.lookaheadChPos(); const nextCh = this.input.charCodeAt(next); // For ambiguous cases, determine if a LexicalDeclaration (or only a // Statement) is allowed here. If context is not empty then only a Statement @@ -130,6 +128,13 @@ export default class StatementParser extends ExpressionParser { return false; } + isDecoratorDeclaration(): boolean { + return ( + this.isContextual("decorator") && + this.lookaheadCh(true) === charCodes.atSign + ); + } + // Parse a single statement. // // If expecting a statement and finding a slash operator, parse a @@ -277,6 +282,16 @@ export default class StatementParser extends ExpressionParser { this.next(); return this.parseFunctionStatement(node, true, !context); } + + if (this.isDecoratorDeclaration()) { + if (context) { + this.unexpected( + null, + "Decorators can only be declared at the top level or inside a block", + ); + } + return this.parseDecoratorDeclaration(node); + } } } @@ -341,8 +356,9 @@ export default class StatementParser extends ExpressionParser { } if ( - this.hasPlugin("decorators") && - !this.getPluginOption("decorators", "decoratorsBeforeExport") + (this.hasPlugin("decorators") && + !this.getPluginOption("decorators", "decoratorsBeforeExport")) || + this.hasPlugin("staticDecorators") ) { this.raise( this.state.start, @@ -359,16 +375,24 @@ export default class StatementParser extends ExpressionParser { } parseDecorator(): N.Decorator { - this.expectOnePlugin(["decorators-legacy", "decorators"]); + this.expectOnePlugin([ + "decorators-legacy", + "decorators", + "staticDecorators", + ]); + + if (this.hasPlugin("staticDecorators")) { + return this.parseStaticDecorator(); + } const node = this.startNode(); this.next(); - if (this.hasPlugin("decorators")) { - // Every time a decorator class expression is evaluated, a new empty array is pushed onto the stack - // So that the decorators of any nested class expressions will be dealt with separately - this.state.decoratorStack.push([]); + // Every time a decorator class expression is evaluated, a new empty array is pushed onto the stack + // So that the decorators of any nested class expressions will be dealt with separately + this.state.decoratorStack.push([]); + if (this.hasPlugin("decorators")) { const startPos = this.state.start; const startLoc = this.state.startLoc; let expr: N.Expression; @@ -389,10 +413,11 @@ export default class StatementParser extends ExpressionParser { } node.expression = this.parseMaybeDecoratorArguments(expr); - this.state.decoratorStack.pop(); - } else { + } else if (this.hasPlugin("decorators-legacy")) { node.expression = this.parseExprSubscripts(); } + + this.state.decoratorStack.pop(); return this.finishNode(node, "Decorator"); } @@ -742,6 +767,78 @@ export default class StatementParser extends ExpressionParser { return this.finishNode(node, "WithStatement"); } + parseDecoratorDeclaration( + node: N.DecoratorDeclaration, + ): N.DecoratorDeclaration { + this.expectPlugin("staticDecorators"); + + this.next(); + + node.id = this.parseDecoratorId(); + this.checkLVal(node.id, BIND_DECORATOR, null, "decorator name"); + + if (this.eat(tt.parenL)) { + // parseBindingList returns $ReadOnlyArray + // but node.params is $ReadOnlyArray. This isn't a problem in + // practice, because if allowModifiers is false it only return Patterns. + // $FlowIgnore + node.params = this.parseBindingList( + tt.parenR, + /* allowEmpty */ false, + /* allowModifiers */ false, + ); + } + + const decorators: N.Decorator[] = []; + + this.expect(tt.braceL); + while (!this.eat(tt.braceR)) { + decorators.push(this.parseDecorator()); + } + + node.body = decorators; + + return this.finishNode(node, "DecoratorDeclaration"); + } + + parseDecoratorId(): N.DecoratorIdentifier { + const node = this.startNode(); + this.expect(tt.at); + this.assertNoSpace("Unexpected space in decorator name"); + + const name = this.parseIdentifierName(node.start, true); + + return this.createIdentifier(node, name, "DecoratorIdentifier"); + } + + parseStaticDecorator(): N.Decorator { + const node: N.Decorator = this.startNode(); + node.id = this.parseDecoratorId(); + + if (this.match(tt.dot)) { + this.raise( + this.state.start, + "Static decorators must be simple identifiers with optional parameters.", + ); + } + + if (this.eat(tt.parenL)) { + // Every time a decorator class expression is evaluated, a new empty array is pushed onto the stack + // So that the decorators of any nested class expressions will be dealt with separately + this.state.decoratorStack.push([]); + + // parseBindingList returns $ReadOnlyArray + // but node.params is $ReadOnlyArray. This isn't a problem in + // practice, because if allowModifiers is false it only return Patterns. + // $FlowIgnore + node.arguments = this.parseExprList(tt.parenR, /* allowEmpty */ true); + + this.state.decoratorStack.pop(); + } + + return this.finishNode(node, "Decorator"); + } + parseEmptyStatement(node: N.EmptyStatement): N.EmptyStatement { this.next(); return this.finishNode(node, "EmptyStatement"); @@ -1737,12 +1834,20 @@ export default class StatementParser extends ExpressionParser { maybeParseExportDeclaration(node: N.Node): boolean { if (this.shouldParseExportDeclaration()) { - if (this.isContextual("async")) { + const isAsync = this.isContextual("async"); + if (isAsync || this.isContextual("decorator")) { const next = this.lookahead(); - // export async; - if (next.type !== tt._function) { - this.unexpected(next.start, `Unexpected token, expected "function"`); + if (isAsync) { + // `export async;` + if (next.type !== tt._function) { + this.unexpected( + next.start, + `Unexpected token, expected "function"`, + ); + } + } else if (next.type !== tt.at) { + this.unexpected(this.state.start, `Unexpected token`); } } @@ -1826,6 +1931,13 @@ export default class StatementParser extends ExpressionParser { isExportDefaultSpecifier(): boolean { if (this.match(tt.name)) { + if (this.isDecoratorDeclaration()) { + this.raise( + this.state.start, + "Decorator declarations are only allowed as named exports.", + ); + } + return this.state.value !== "async" && this.state.value !== "let"; } @@ -1844,12 +1956,10 @@ export default class StatementParser extends ExpressionParser { if (this.eatContextual("from")) { node.source = this.parseImportSource(); this.checkExport(node); + } else if (expect) { + this.unexpected(this.state.start, `Unexpected token, expected "from"`); } else { - if (expect) { - this.unexpected(); - } else { - node.source = null; - } + node.source = null; } this.semicolon(); @@ -1857,7 +1967,11 @@ export default class StatementParser extends ExpressionParser { shouldParseExportDeclaration(): boolean { if (this.match(tt.at)) { - this.expectOnePlugin(["decorators", "decorators-legacy"]); + this.expectOnePlugin([ + "decorators", + "decorators-legacy", + "staticDecorators", + ]); if (this.hasPlugin("decorators")) { if (this.getPluginOption("decorators", "decoratorsBeforeExport")) { this.unexpected( @@ -1870,6 +1984,8 @@ export default class StatementParser extends ExpressionParser { return true; } } + + return this.hasPlugin("staticDecorators"); } return ( @@ -1878,7 +1994,8 @@ export default class StatementParser extends ExpressionParser { this.state.type.keyword === "function" || this.state.type.keyword === "class" || this.isLet() || - this.isAsyncFunction() + this.isAsyncFunction() || + this.isDecoratorDeclaration() ); } @@ -2005,17 +2122,34 @@ export default class StatementParser extends ExpressionParser { if (this.eat(tt.braceR)) break; } - const node = this.startNode(); - node.local = this.parseIdentifier(true); - node.exported = this.eatContextual("as") - ? this.parseIdentifier(true) - : node.local.__clone(); - nodes.push(this.finishNode(node, "ExportSpecifier")); + nodes.push(this.parseExportSpecifier()); } return nodes; } + parseExportSpecifier(): N.ExportSpecifier { + const specifier: N.ExportSpecifier = this.startNode(); + + const isDecorator = this.match(tt.at); + if (isDecorator) { + this.expectPlugin("staticDecorators"); + specifier.local = this.parseDecoratorId(); + } else { + specifier.local = this.parseIdentifier(true); + } + + if (this.eatContextual("as")) { + specifier.exported = isDecorator + ? this.parseDecoratorId() + : this.parseIdentifier(true); + } else { + specifier.exported = specifier.local.__clone(); + } + + return this.finishNode(specifier, "ExportSpecifier"); + } + // Parses import declaration. parseImport(node: N.Node): N.AnyImport { @@ -2040,7 +2174,12 @@ export default class StatementParser extends ExpressionParser { // eslint-disable-next-line no-unused-vars shouldParseDefaultImport(node: N.ImportDeclaration): boolean { - return this.match(tt.name); + return ( + this.match(tt.name) || + // Decorators are not actually allowed here, but + // parseImportSpecifierLocal will throw a nice error + this.match(tt.at) + ); } parseImportSpecifierLocal( @@ -2049,7 +2188,16 @@ export default class StatementParser extends ExpressionParser { type: string, contextDescription: string, ): void { - specifier.local = this.parseIdentifier(); + if (this.match(tt.at)) { + this.expectPlugin("staticDecorators"); + this.unexpected( + this.state.start, + "Invalid decorator in " + contextDescription, + ); + } else { + specifier.local = this.parseIdentifier(); + } + this.checkLVal( specifier.local, BIND_LEXICAL, @@ -2115,22 +2263,34 @@ export default class StatementParser extends ExpressionParser { } parseImportSpecifier(node: N.ImportDeclaration): void { - const specifier = this.startNode(); - specifier.imported = this.parseIdentifier(true); + const specifier: N.ImportSpecifier = this.startNode(); + + const isDecorator = this.match(tt.at); + if (isDecorator) { + this.expectPlugin("staticDecorators"); + specifier.imported = this.parseDecoratorId(); + } else { + specifier.imported = this.parseIdentifier(true); + } + if (this.eatContextual("as")) { - specifier.local = this.parseIdentifier(); + specifier.local = isDecorator + ? this.parseDecoratorId() + : this.parseIdentifier(); } else { - this.checkReservedWord( - specifier.imported.name, - specifier.start, - true, - true, - ); + if (!isDecorator) { + this.checkReservedWord( + specifier.imported.name, + specifier.start, + true, + true, + ); + } specifier.local = specifier.imported.__clone(); } this.checkLVal( specifier.local, - BIND_LEXICAL, + isDecorator ? BIND_DECORATOR : BIND_LEXICAL, undefined, "import specifier", ); diff --git a/packages/babel-parser/src/plugin-utils.js b/packages/babel-parser/src/plugin-utils.js index c1cb6a6b7e92..fe4d8ef6fefe 100644 --- a/packages/babel-parser/src/plugin-utils.js +++ b/packages/babel-parser/src/plugin-utils.js @@ -41,6 +41,19 @@ export function getPluginOption( const PIPELINE_PROPOSALS = ["minimal", "smart", "fsharp"]; export function validatePlugins(plugins: PluginList) { + if (hasPlugin(plugins, "staticDecorators")) { + if (hasPlugin(plugins, "decorators")) { + throw new Error( + "Cannot use the decorators and staticDecorators plugins together", + ); + } + if (hasPlugin(plugins, "decorators-legacy")) { + throw new Error( + "Cannot use the decorators-legacy and staticDecorators plugins together", + ); + } + } + if (hasPlugin(plugins, "decorators")) { if (hasPlugin(plugins, "decorators-legacy")) { throw new Error( diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js index 5d6922d329eb..c99e37abc02c 100644 --- a/packages/babel-parser/src/plugins/typescript/index.js +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -1323,6 +1323,12 @@ export default (superClass: Class): Class => case "declare": { const declaration = this.tsTryParseDeclare(node); if (declaration) { + if (declaration.type === "DecoratorDeclaration") { + throw this.raise( + declaration.start, + `TypeScript's "declare" doesn't support decorator declarations`, + ); + } declaration.declare = true; return declaration; } @@ -1977,6 +1983,13 @@ export default (superClass: Class): Class => // Reset location to include `declare` in range this.resetStartLocation(declaration, startPos, startLoc); + if (declaration.type === "DecoratorDeclaration") { + throw this.raise( + declaration.start, + `TypeScript's "declare" doesn't support decorator declarations`, + ); + } + declaration.declare = true; } diff --git a/packages/babel-parser/src/plugins/typescript/scope.js b/packages/babel-parser/src/plugins/typescript/scope.js index 085b90e73496..81f70c3f6d0f 100644 --- a/packages/babel-parser/src/plugins/typescript/scope.js +++ b/packages/babel-parser/src/plugins/typescript/scope.js @@ -94,10 +94,11 @@ export default class TypeScriptScopeHandler extends ScopeHandler, + body: $ReadOnlyArray, +}; + export type Decorator = NodeBase & { type: "Decorator", + + // NOTE: expression is used for "decorators" and "legacy-decorators", + // name is used for "staticDecorators" + expression: Expression, + id: DecoratorIdentifier, + arguments?: Array, }; +export type DecoratorIdentifier = NodeBase & { + type: "DecoratorIdentifier", + name: string, + + __clone(): DecoratorIdentifier, +}; + export type Directive = NodeBase & { type: "Directive", value: DirectiveLiteral, @@ -800,7 +821,7 @@ export type AnyExport = | TsNamespaceExportDeclaration; export type ModuleSpecifier = NodeBase & { - local: Identifier, + local: Identifier | DecoratorIdentifier, }; // Imports @@ -818,7 +839,7 @@ export type ImportDeclaration = NodeBase & { export type ImportSpecifier = ModuleSpecifier & { type: "ImportSpecifier", - imported: Identifier, + imported: Identifier | DecoratorIdentifier, }; export type ImportDefaultSpecifier = ModuleSpecifier & { @@ -842,13 +863,13 @@ export type ExportNamedDeclaration = NodeBase & { export type ExportSpecifier = NodeBase & { type: "ExportSpecifier", - exported: Identifier, - local: Identifier, + exported: Identifier | DecoratorIdentifier, + local: Identifier | DecoratorIdentifier, }; export type ExportDefaultSpecifier = NodeBase & { type: "ExportDefaultSpecifier", - exported: Identifier, + exported: Identifier | DecoratorIdentifier, }; export type ExportDefaultDeclaration = NodeBase & { @@ -857,6 +878,7 @@ export type ExportDefaultDeclaration = NodeBase & { | OptFunctionDeclaration | OptTSDeclareFunction | OptClassDeclaration + | DecoratorDeclaration | Expression, }; diff --git a/packages/babel-parser/src/util/scope.js b/packages/babel-parser/src/util/scope.js index e40cb53e3e33..5df2188c63a3 100644 --- a/packages/babel-parser/src/util/scope.js +++ b/packages/babel-parser/src/util/scope.js @@ -14,6 +14,7 @@ import { BIND_SCOPE_VAR, BIND_SCOPE_LEXICAL, BIND_KIND_VALUE, + BIND_KIND_DECORATOR, type ScopeFlags, type BindingTypes, } from "./scopeflags"; @@ -28,6 +29,8 @@ export class Scope { lexical: string[] = []; // A list of lexically-declared FunctionDeclaration names in the current lexical scope functions: string[] = []; + // A list of decorator names in the current lexical scope + decorators: string[] = []; constructor(flags: ScopeFlags) { this.flags = flags; @@ -102,11 +105,12 @@ export default class ScopeHandler { if (bindingType & BIND_SCOPE_FUNCTION) { scope.functions.push(name); + this.maybeExportDefined(scope, name); + } else if (bindingType & BIND_KIND_DECORATOR) { + scope.decorators.push(name); + this.maybeExportDefined(scope, "@" + name); } else { scope.lexical.push(name); - } - - if (bindingType & BIND_SCOPE_LEXICAL) { this.maybeExportDefined(scope, name); } } else if (bindingType & BIND_SCOPE_VAR) { @@ -119,9 +123,6 @@ export default class ScopeHandler { if (scope.flags & SCOPE_VAR) break; } } - if (this.inModule && scope.flags & SCOPE_PROGRAM) { - this.undefinedExports.delete(name); - } } maybeExportDefined(scope: IScope, name: string) { @@ -137,7 +138,11 @@ export default class ScopeHandler { pos: number, ) { if (this.isRedeclaredInScope(scope, name, bindingType)) { - this.raise(pos, `Identifier '${name}' has already been declared`); + const prefix = bindingType & BIND_KIND_DECORATOR ? "@" : ""; + this.raise( + pos, + `Identifier '${prefix}${name}' has already been declared`, + ); } } @@ -146,6 +151,10 @@ export default class ScopeHandler { name: string, bindingType: BindingTypes, ): boolean { + if (bindingType & BIND_KIND_DECORATOR) { + return scope.decorators.indexOf(name) > -1; + } + if (!(bindingType & BIND_KIND_VALUE)) return false; if (bindingType & BIND_SCOPE_LEXICAL) { @@ -172,7 +181,14 @@ export default class ScopeHandler { ); } - checkLocalExport(id: N.Identifier) { + checkLocalExport(id: N.Identifier | N.DecoratorIdentifier) { + if (id.type === "DecoratorIdentifier") { + if (this.scopeStack[0].decorators.indexOf(id.name) === -1) { + this.undefinedExports.set("@" + id.name, id.start); + } + return; + } + if ( this.scopeStack[0].lexical.indexOf(id.name) === -1 && this.scopeStack[0].var.indexOf(id.name) === -1 && diff --git a/packages/babel-parser/src/util/scopeflags.js b/packages/babel-parser/src/util/scopeflags.js index 43b18f6641e1..efb66d74f2f8 100644 --- a/packages/babel-parser/src/util/scopeflags.js +++ b/packages/babel-parser/src/util/scopeflags.js @@ -37,20 +37,21 @@ export function functionFlags(isAsync: boolean, isGenerator: boolean) { // These flags are meant to be _only_ used inside the Scope class (or subclasses). // prettier-ignore -export const BIND_KIND_VALUE = 0b00000_0000_01, - BIND_KIND_TYPE = 0b00000_0000_10, +export const BIND_KIND_VALUE = 0b00000_0000_001, + BIND_KIND_TYPE = 0b00000_0000_010, + BIND_KIND_DECORATOR = 0b00000_0000_100, // Used in checkLVal and declareName to determine the type of a binding - BIND_SCOPE_VAR = 0b00000_0001_00, // Var-style binding - BIND_SCOPE_LEXICAL = 0b00000_0010_00, // Let- or const-style binding - BIND_SCOPE_FUNCTION = 0b00000_0100_00, // Function declaration - BIND_SCOPE_OUTSIDE = 0b00000_1000_00, // Special case for function names as + BIND_SCOPE_VAR = 0b00000_0001_000, // Var-style binding + BIND_SCOPE_LEXICAL = 0b00000_0010_000, // Let- or const-style binding + BIND_SCOPE_FUNCTION = 0b00000_0100_000, // Function declaration + BIND_SCOPE_OUTSIDE = 0b00000_1000_000, // Special case for function names as // bound inside the function // Misc flags - BIND_FLAGS_NONE = 0b00001_0000_00, - BIND_FLAGS_CLASS = 0b00010_0000_00, - BIND_FLAGS_TS_ENUM = 0b00100_0000_00, - BIND_FLAGS_TS_CONST_ENUM = 0b01000_0000_00, - BIND_FLAGS_TS_EXPORT_ONLY = 0b10000_0000_00; + BIND_FLAGS_NONE = 0b00001_0000_000, + BIND_FLAGS_CLASS = 0b00010_0000_000, + BIND_FLAGS_TS_ENUM = 0b00100_0000_000, + BIND_FLAGS_TS_CONST_ENUM = 0b01000_0000_000, + BIND_FLAGS_TS_EXPORT_ONLY = 0b10000_0000_000; // These flags are meant to be _only_ used by Scope consumers // prettier-ignore @@ -59,6 +60,7 @@ export const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_ BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0 , BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0 , BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0 , + BIND_DECORATOR = BIND_KIND_DECORATOR | BIND_SCOPE_LEXICAL | 0 , BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS , BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0 , BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM, @@ -78,6 +80,7 @@ export type BindingTypes = | typeof BIND_LEXICAL | typeof BIND_CLASS | typeof BIND_FUNCTION + | typeof BIND_DECORATOR | typeof BIND_TS_INTERFACE | typeof BIND_TS_TYPE | typeof BIND_TS_ENUM diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/84/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/84/options.json index d56be40ce7c0..06b2a712bcc5 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/84/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/84/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "Unexpected token (1:8)" + "throws": "Unexpected token, expected \"from\" (1:8)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-batch-missing-from-clause/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-batch-missing-from-clause/options.json index 9ce9658f7dfa..af96daee1f5d 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-batch-missing-from-clause/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-batch-missing-from-clause/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:8)" + "throws": "Unexpected token, expected \"from\" (1:8)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-batch-token/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-batch-token/options.json index 2a28555f76db..9358dff89038 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-batch-token/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-batch-token/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:9)" + "throws": "Unexpected token, expected \"from\" (1:9)" } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json index 11f94afa3b7a..b46a8ce67e47 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json @@ -1,4 +1,4 @@ { - "throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (1:0)", + "throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators, staticDecorators' (1:0)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-2/export-decorated-class-without-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/decorators-2/export-decorated-class-without-plugin/options.json index 5a8bd1e83883..e4e5a52ed9a2 100644 --- a/packages/babel-parser/test/fixtures/experimental/decorators-2/export-decorated-class-without-plugin/options.json +++ b/packages/babel-parser/test/fixtures/experimental/decorators-2/export-decorated-class-without-plugin/options.json @@ -1,5 +1,5 @@ { "sourceType": "module", - "throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'decorators, decorators-legacy' (1:7)", + "throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'decorators, decorators-legacy, staticDecorators' (1:7)", "plugins": null } diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-declaration/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-declaration/input.js new file mode 100644 index 000000000000..58192b34e580 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-declaration/input.js @@ -0,0 +1,2 @@ +decorator @foo {} +decorator @foo {} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-declaration/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-declaration/options.json new file mode 100644 index 000000000000..28823ba65675 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-declaration/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "staticDecorators" + ], + "throws": "Identifier '@foo' has already been declared (2:10)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-import/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-import/input.js new file mode 100644 index 000000000000..41dc520f0623 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-import/input.js @@ -0,0 +1,2 @@ +decorator @foo {} +import { @foo } from "x"; diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-import/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-import/options.json new file mode 100644 index 000000000000..18829db69d7f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-declaration-import/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["staticDecorators"], + "throws": "Identifier '@foo' has already been declared (2:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-declaration/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-declaration/input.js new file mode 100644 index 000000000000..0a833da25769 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-declaration/input.js @@ -0,0 +1,2 @@ +import { @foo } from "x"; +decorator @foo {} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-declaration/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-declaration/options.json new file mode 100644 index 000000000000..46f3764671e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-declaration/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["staticDecorators"], + "throws": "Identifier '@foo' has already been declared (2:10)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-import/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-import/input.js new file mode 100644 index 000000000000..f9bb3ad1b6d2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-import/input.js @@ -0,0 +1,2 @@ +import { @foo } from "x"; +import { @foo } from "x"; diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-import/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-import/options.json new file mode 100644 index 000000000000..18829db69d7f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-duplicated-import-import/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["staticDecorators"], + "throws": "Identifier '@foo' has already been declared (2:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-after/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-after/input.js new file mode 100644 index 000000000000..07054b1792b2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-after/input.js @@ -0,0 +1,2 @@ +decorator @foo {} +export { @foo }; diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-after/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-after/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-after/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-after/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-after/output.json new file mode 100644 index 000000000000..e6b9f28d05e8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-after/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": [] + }, + { + "type": "ExportNamedDeclaration", + "start": 18, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "local": { + "type": "DecoratorIdentifier", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "exported": { + "type": "DecoratorIdentifier", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-before/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-before/input.js new file mode 100644 index 000000000000..fa91ddfb368a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-before/input.js @@ -0,0 +1,2 @@ +export { @foo }; +decorator @foo {} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-before/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-before/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-before/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-before/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-before/output.json new file mode 100644 index 000000000000..595dde4d7141 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-before/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "local": { + "type": "DecoratorIdentifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "exported": { + "type": "DecoratorIdentifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ], + "source": null, + "declaration": null + }, + { + "type": "DecoratorDeclaration", + "start": 17, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-after-lexical/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-after-lexical/input.js new file mode 100644 index 000000000000..f5666950c8d5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-after-lexical/input.js @@ -0,0 +1,2 @@ +let foo; +export { @foo }; diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-after-lexical/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-after-lexical/options.json new file mode 100644 index 000000000000..bfa0d3484b9c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-after-lexical/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export '@foo' is not defined (2:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-before-lexical/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-before-lexical/input.js new file mode 100644 index 000000000000..506b220d0428 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-before-lexical/input.js @@ -0,0 +1,2 @@ +export { @foo }; +let foo; diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-before-lexical/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-before-lexical/options.json new file mode 100644 index 000000000000..9074c6a4cbda --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-decorator-before-lexical/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export '@foo' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-after-decorator/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-after-decorator/input.js new file mode 100644 index 000000000000..094caca95424 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-after-decorator/input.js @@ -0,0 +1,2 @@ +decorator @foo {} +export { foo }; diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-after-decorator/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-after-decorator/options.json new file mode 100644 index 000000000000..ee437d26fe62 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-after-decorator/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'foo' is not defined (2:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-before-decorator/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-before-decorator/input.js new file mode 100644 index 000000000000..580279f55e17 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-before-decorator/input.js @@ -0,0 +1,2 @@ +export { foo }; +decorator @foo {} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-before-decorator/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-before-decorator/options.json new file mode 100644 index 000000000000..e9bceb98a672 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-export-lexical-before-decorator/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'foo' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-1/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-1/input.js new file mode 100644 index 000000000000..0bf9c82becfe --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-1/input.js @@ -0,0 +1,2 @@ +let foo; +decorator @foo {} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-1/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-1/output.json new file mode 100644 index 000000000000..40d263269827 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-1/output.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "DecoratorDeclaration", + "start": 9, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 19, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-2/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-2/input.js new file mode 100644 index 000000000000..634de7968fdf --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-2/input.js @@ -0,0 +1,2 @@ +decorator @foo {} +let foo; diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-2/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-2/output.json new file mode 100644 index 000000000000..dc3b8194f2f1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-same-name-lexical-2/output.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": [] + }, + { + "type": "VariableDeclaration", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-1/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-1/input.js new file mode 100644 index 000000000000..61c5cfcc9fe3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-1/input.js @@ -0,0 +1,4 @@ +decorator @foo {} +{ + decorator @foo {} +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-1/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-1/output.json new file mode 100644 index 000000000000..f82687ed4108 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-1/output.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": [] + }, + { + "type": "BlockStatement", + "start": 18, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 22, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 32, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 16 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": [] + } + ], + "directives": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-2/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-2/input.js new file mode 100644 index 000000000000..8f00831e7b36 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-2/input.js @@ -0,0 +1,4 @@ +{ + decorator @foo {} +} +decorator @foo {} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-2/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-2/output.json new file mode 100644 index 000000000000..1ec83c0828d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/binding-shadowed-2/output.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "BlockStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 4, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 14, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": [] + } + ], + "directives": [] + }, + { + "type": "DecoratorDeclaration", + "start": 24, + "end": 41, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 34, + "end": 38, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-newline/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-newline/input.js new file mode 100644 index 000000000000..c70f8a3e5c44 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-newline/input.js @@ -0,0 +1,2 @@ +decorator +@foo() {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-newline/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-newline/options.json new file mode 100644 index 000000000000..9321e8323d64 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-newline/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Leading decorators must be attached to a class declaration (2:7)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-space/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-space/input.js new file mode 100644 index 000000000000..94a1bb3de557 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-space/input.js @@ -0,0 +1 @@ +decorator @ foo () {} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-space/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-space/options.json new file mode 100644 index 000000000000..86d7c27e79d2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-no-space/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected space in decorator name (1:11)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-default/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-default/input.js new file mode 100644 index 000000000000..0b9f4e5478e8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-default/input.js @@ -0,0 +1 @@ +decorator @foo(a = 2) {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-default/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-default/output.json new file mode 100644 index 000000000000..bb816a870976 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-default/output.json @@ -0,0 +1,122 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "params": [ + { + "type": "AssignmentPattern", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "left": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + "right": { + "type": "NumericLiteral", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ], + "body": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-destructuring/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-destructuring/input.js new file mode 100644 index 000000000000..9201c6b2b2fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-destructuring/input.js @@ -0,0 +1 @@ +decorator @foo({ bar }, [ baz ]) {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-destructuring/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-destructuring/output.json new file mode 100644 index 000000000000..2c094ea79d48 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-destructuring/output.json @@ -0,0 +1,176 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "params": [ + { + "type": "ObjectPattern", + "start": 15, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "extra": { + "shorthand": true + } + } + ] + }, + { + "type": "ArrayPattern", + "start": 24, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "baz" + }, + "name": "baz" + } + ] + } + ], + "body": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-empty/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-empty/input.js new file mode 100644 index 000000000000..dec49c93578e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-empty/input.js @@ -0,0 +1 @@ +decorator @foo() {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-empty/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-empty/output.json new file mode 100644 index 000000000000..49826392c627 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-empty/output.json @@ -0,0 +1,69 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "params": [], + "body": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-no-any-expression/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-no-any-expression/input.js new file mode 100644 index 000000000000..c39e075236d8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-no-any-expression/input.js @@ -0,0 +1 @@ +decorator @foo(a.b) {} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-no-any-expression/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-no-any-expression/options.json new file mode 100644 index 000000000000..9eb147289687 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-no-any-expression/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["staticDecorators"], + "throws": "Unexpected token, expected \",\" (1:16)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-omitted/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-omitted/input.js new file mode 100644 index 000000000000..ddff150e8100 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-omitted/input.js @@ -0,0 +1 @@ +decorator @foo {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-omitted/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-omitted/output.json new file mode 100644 index 000000000000..698c996e155a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-omitted/output.json @@ -0,0 +1,68 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-rest/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-rest/input.js new file mode 100644 index 000000000000..ef5056b5de89 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-rest/input.js @@ -0,0 +1 @@ +decorator @foo(a, b, ...c) {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-rest/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-rest/output.json new file mode 100644 index 000000000000..bc56e082ded8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-rest/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b" + }, + { + "type": "RestElement", + "start": 21, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "argument": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ], + "body": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-trailing-comma/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-trailing-comma/input.js new file mode 100644 index 000000000000..88fa95b8a686 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-trailing-comma/input.js @@ -0,0 +1 @@ +decorator @foo(a,) {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-trailing-comma/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-trailing-comma/output.json new file mode 100644 index 000000000000..2c8f50a61ea8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-params-trailing-comma/output.json @@ -0,0 +1,87 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a" + } + ], + "body": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-valid-newline/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-valid-newline/input.js new file mode 100644 index 000000000000..7e094f2d92e4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-valid-newline/input.js @@ -0,0 +1,6 @@ +decorator @foo +() +{} + +decorator @bar +{} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-valid-newline/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-valid-newline/output.json new file mode 100644 index 000000000000..cd750507d125 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/declaration-valid-newline/output.json @@ -0,0 +1,102 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "params": [], + "body": [] + }, + { + "type": "DecoratorDeclaration", + "start": 22, + "end": 39, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 32, + "end": 36, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 14 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "body": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-alias/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-alias/input.js new file mode 100644 index 000000000000..cbc41ae0e90c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-alias/input.js @@ -0,0 +1,2 @@ +decorator @dec {} +export { @dec as @foo }; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-alias/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-alias/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-alias/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-alias/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-alias/output.json new file mode 100644 index 000000000000..de9498588dfa --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-alias/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "dec" + }, + "name": "dec" + }, + "body": [] + }, + { + "type": "ExportNamedDeclaration", + "start": 18, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 27, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "local": { + "type": "DecoratorIdentifier", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "dec" + }, + "name": "dec" + }, + "exported": { + "type": "DecoratorIdentifier", + "start": 35, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 21 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-declaration/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-declaration/input.js new file mode 100644 index 000000000000..9a81ff88a7f4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-declaration/input.js @@ -0,0 +1 @@ +export decorator @foo {} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-declaration/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-declaration/options.json new file mode 100644 index 000000000000..2e5a7fa7de3f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-declaration/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Decorator declarations are only allowed as named exports. (1:7)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-alias/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-alias/input.js new file mode 100644 index 000000000000..ce3359c95bf5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-alias/input.js @@ -0,0 +1 @@ +export { @foo as @bar } from "mod"; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-alias/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-alias/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-alias/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-alias/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-alias/output.json new file mode 100644 index 000000000000..a45f40126c11 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-alias/output.json @@ -0,0 +1,122 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "local": { + "type": "DecoratorIdentifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "exported": { + "type": "DecoratorIdentifier", + "start": 17, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "bar" + }, + "name": "bar" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 29, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "extra": { + "rawValue": "mod", + "raw": "\"mod\"" + }, + "value": "mod" + }, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-default/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-default/input.js new file mode 100644 index 000000000000..b092db3add08 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-default/input.js @@ -0,0 +1 @@ +export @dec from "mod"; diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-default/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-default/options.json new file mode 100644 index 000000000000..5d19db608851 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-default/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["staticDecorators", "exportDefaultFrom"], + "throws": "Leading decorators must be attached to a class declaration (1:12)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-named/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-named/input.js new file mode 100644 index 000000000000..96c8c3d79b60 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-named/input.js @@ -0,0 +1 @@ +export { @foo } from "mod"; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-named/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-named/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-named/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-named/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-named/output.json new file mode 100644 index 000000000000..6e9ef89e78c3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-from-named/output.json @@ -0,0 +1,122 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "local": { + "type": "DecoratorIdentifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "exported": { + "type": "DecoratorIdentifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "extra": { + "rawValue": "mod", + "raw": "\"mod\"" + }, + "value": "mod" + }, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-named/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-named/input.js new file mode 100644 index 000000000000..700acca7a6db --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-named/input.js @@ -0,0 +1,2 @@ +decorator @dec {} +export { @dec }; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-named/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-named/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-named/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/export-named/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-named/output.json new file mode 100644 index 000000000000..82ee58543b13 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/export-named/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DecoratorDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "dec" + }, + "name": "dec" + }, + "body": [] + }, + { + "type": "ExportNamedDeclaration", + "start": 18, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "local": { + "type": "DecoratorIdentifier", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "dec" + }, + "name": "dec" + }, + "exported": { + "type": "DecoratorIdentifier", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "dec" + }, + "name": "dec" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/import-alias/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-alias/input.js new file mode 100644 index 000000000000..1d32cef15743 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-alias/input.js @@ -0,0 +1 @@ +import { @foo as @bar } from "mod"; diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/import-alias/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-alias/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-alias/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/import-alias/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-alias/output.json new file mode 100644 index 000000000000..549e0d085d86 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-alias/output.json @@ -0,0 +1,121 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 9, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "imported": { + "type": "DecoratorIdentifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "local": { + "type": "DecoratorIdentifier", + "start": 17, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "bar" + }, + "name": "bar" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 29, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "extra": { + "rawValue": "mod", + "raw": "\"mod\"" + }, + "value": "mod" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/import-default/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-default/input.js new file mode 100644 index 000000000000..e945cc2ccd7f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-default/input.js @@ -0,0 +1 @@ +import @dec from "mod"; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/import-default/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-default/options.json new file mode 100644 index 000000000000..d3c9d28fc5b2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-default/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Invalid decorator in default import specifier (1:7)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/import-named/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-named/input.js new file mode 100644 index 000000000000..5d0d9e2333a3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-named/input.js @@ -0,0 +1 @@ +import { @foo } from "mod"; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/import-named/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-named/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-named/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/import-named/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-named/output.json new file mode 100644 index 000000000000..a10587eb79d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/import-named/output.json @@ -0,0 +1,121 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "imported": { + "type": "DecoratorIdentifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "local": { + "type": "DecoratorIdentifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "extra": { + "rawValue": "mod", + "raw": "\"mod\"" + }, + "value": "mod" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-declaration/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-declaration/input.js new file mode 100644 index 000000000000..dc01cee959ca --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-declaration/input.js @@ -0,0 +1 @@ +decorator @dec {} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-declaration/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-declaration/options.json new file mode 100644 index 000000000000..fd8aedeccd22 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-declaration/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [], + "throws": "This experimental syntax requires enabling the parser plugin: 'staticDecorators' (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-default/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-default/input.js new file mode 100644 index 000000000000..e945cc2ccd7f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-default/input.js @@ -0,0 +1 @@ +import @dec from "mod"; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-default/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-default/options.json new file mode 100644 index 000000000000..aed9a5f9bc9b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-default/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [], + "throws": "This experimental syntax requires enabling the parser plugin: 'staticDecorators' (1:7)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-named/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-named/input.js new file mode 100644 index 000000000000..b1678daa167f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-named/input.js @@ -0,0 +1 @@ +import { @dec } from "mod"; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-named/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-named/options.json new file mode 100644 index 000000000000..b5e56c6efbc2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-import-named/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [], + "throws": "This experimental syntax requires enabling the parser plugin: 'staticDecorators' (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-usage/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-usage/input.js new file mode 100644 index 000000000000..1a7c66df32c4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-usage/input.js @@ -0,0 +1,3 @@ +class A { + @dec foo() {} +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-usage/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-usage/options.json new file mode 100644 index 000000000000..cc5c766c34dd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/no-plugin-usage/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [], + "throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators, staticDecorators' (2:2)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/options.json new file mode 100644 index 000000000000..2d909862898f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["staticDecorators"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-multiple/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-multiple/input.js new file mode 100644 index 000000000000..1fd6a5d65465 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-multiple/input.js @@ -0,0 +1,4 @@ +@a @b +class Foo { + @c @d bar() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-multiple/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-multiple/output.json new file mode 100644 index 000000000000..a2e28d9e5e90 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-multiple/output.json @@ -0,0 +1,273 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "a" + }, + "name": "a" + } + }, + { + "type": "Decorator", + "start": 3, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 3, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + } + } + ], + "id": { + "type": "Identifier", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 16, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 20, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "c" + }, + "name": "c" + } + }, + { + "type": "Decorator", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "d" + }, + "name": "d" + } + } + ], + "static": false, + "key": { + "type": "Identifier", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 32, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-nested/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-nested/input.js new file mode 100644 index 000000000000..cd0ee7580456 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-nested/input.js @@ -0,0 +1,6 @@ +class A { + @dec(class B { + @dec b() {} + }) + a() {} +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-nested/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-nested/output.json new file mode 100644 index 000000000000..8c402519a011 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-nested/output.json @@ -0,0 +1,317 @@ +{ + "type": "File", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 56, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 12, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "dec" + }, + "name": "dec" + }, + "arguments": [ + { + "type": "ClassExpression", + "start": 17, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "B" + }, + "name": "B" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 25, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 31, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 31, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 31, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "dec" + }, + "name": "dec" + } + } + ], + "static": false, + "key": { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ] + } + ], + "static": false, + "key": { + "type": "Identifier", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 54, + "end": 56, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-params/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-params/input.js new file mode 100644 index 000000000000..d91043b0d85a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-params/input.js @@ -0,0 +1,4 @@ +class A { + @dec + foo() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-params/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-params/output.json new file mode 100644 index 000000000000..4f7ab12c7e9d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-params/output.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "dec" + }, + "name": "dec" + } + } + ], + "static": false, + "key": { + "type": "Identifier", + "start": 19, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 25, + "end": 27, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-space/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-space/input.js new file mode 100644 index 000000000000..b71c1aa96ecc --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-space/input.js @@ -0,0 +1,4 @@ +class A { + @ dec + foo() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-space/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-space/options.json new file mode 100644 index 000000000000..02d8ffa47340 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-no-space/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "staticDecorators" + ], + "throws": "Unexpected space in decorator name (2:3)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-class/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-class/input.js new file mode 100644 index 000000000000..b0a6889b47ed --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-class/input.js @@ -0,0 +1,2 @@ +@dec +class A {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-class/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-class/output.json new file mode 100644 index 000000000000..b59bf5d6f1cc --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-class/output.json @@ -0,0 +1,118 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "dec" + }, + "name": "dec" + } + } + ], + "id": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-computed/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-computed/input.js new file mode 100644 index 000000000000..2a6963943a7c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-computed/input.js @@ -0,0 +1,3 @@ +class A { + @dec [foo]() {} +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-computed/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-computed/output.json new file mode 100644 index 000000000000..1afc3bab0d30 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-computed/output.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "dec" + }, + "name": "dec" + } + } + ], + "static": false, + "computed": true, + "key": { + "type": "Identifier", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 25, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-field/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-field/input.js new file mode 100644 index 000000000000..4e930c88754a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-field/input.js @@ -0,0 +1,3 @@ +class A { + @dec foo; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-field/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-field/options.json new file mode 100644 index 000000000000..2d2c7dd3b6d4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["staticDecorators", "classProperties"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-field/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-field/output.json new file mode 100644 index 000000000000..bf3a005038b0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-field/output.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 12, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "dec" + }, + "name": "dec" + } + } + ], + "static": false, + "key": { + "type": "Identifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-generator/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-generator/input.js new file mode 100644 index 000000000000..47fc00b089a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-generator/input.js @@ -0,0 +1,3 @@ +class A { + @dec *gen() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-generator/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-generator/output.json new file mode 100644 index 000000000000..4358fa80e10a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-generator/output.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "dec" + }, + "name": "dec" + } + } + ], + "static": false, + "kind": "method", + "key": { + "type": "Identifier", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "gen" + }, + "name": "gen" + }, + "computed": false, + "id": null, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-private/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-private/input.js new file mode 100644 index 000000000000..a12b921a6b39 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-private/input.js @@ -0,0 +1,3 @@ +class A { + @dec #foo() {} +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-private/options.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-private/options.json new file mode 100644 index 000000000000..7a8104da333c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-private/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["staticDecorators", "classPrivateMethods"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-private/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-private/output.json new file mode 100644 index 000000000000..3552482fad19 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-on-private/output.json @@ -0,0 +1,189 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "dec" + }, + "name": "dec" + } + } + ], + "static": false, + "key": { + "type": "PrivateName", + "start": 17, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "foo" + }, + "name": "foo" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-any-expression/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-any-expression/input.js new file mode 100644 index 000000000000..fbcb3fffb367 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-any-expression/input.js @@ -0,0 +1,4 @@ +class A { + @dec(a + b[c]) + foo() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-any-expression/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-any-expression/output.json new file mode 100644 index 000000000000..b1c387b7853a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-any-expression/output.json @@ -0,0 +1,260 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "dec" + }, + "name": "dec" + }, + "arguments": [ + { + "type": "BinaryExpression", + "start": 17, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "+", + "right": { + "type": "MemberExpression", + "start": 21, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "object": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "b" + }, + "name": "b" + }, + "property": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "c" + }, + "name": "c" + }, + "computed": true + } + } + ] + } + ], + "static": false, + "key": { + "type": "Identifier", + "start": 29, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 35, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-empty/input.js b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-empty/input.js new file mode 100644 index 000000000000..c0db06d0641a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-empty/input.js @@ -0,0 +1,4 @@ +class A { + @dec() + foo() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-empty/output.json b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-empty/output.json new file mode 100644 index 000000000000..875d7a1f4982 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/static-decorators/usage-params-empty/output.json @@ -0,0 +1,176 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "DecoratorIdentifier", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "dec" + }, + "name": "dec" + }, + "arguments": [] + } + ], + "static": false, + "key": { + "type": "Identifier", + "start": 21, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/typings/babel-parser.d.ts b/packages/babel-parser/typings/babel-parser.d.ts index 799e9e8945d1..03df7098542e 100644 --- a/packages/babel-parser/typings/babel-parser.d.ts +++ b/packages/babel-parser/typings/babel-parser.d.ts @@ -8,137 +8,144 @@ /** * Parse the provided code as an entire ECMAScript program. */ -export function parse(input: string, options?: ParserOptions): import('@babel/types').File; +export function parse( + input: string, + options?: ParserOptions +): import("@babel/types").File; /** * Parse the provided code as a single expression. */ -export function parseExpression(input: string, options?: ParserOptions): import('@babel/types').Expression; +export function parseExpression( + input: string, + options?: ParserOptions +): import("@babel/types").Expression; export interface ParserOptions { - /** - * By default, import and export declarations can only appear at a program's top level. - * Setting this option to true allows them anywhere where a statement is allowed. - */ - allowImportExportEverywhere?: boolean; - - /** - * By default, await use is not allowed outside of an async function. - * Set this to true to accept such code. - */ - allowAwaitOutsideFunction?: boolean; - - /** - * By default, a return statement at the top level raises an error. - * Set this to true to accept such code. - */ - allowReturnOutsideFunction?: boolean; - - allowSuperOutsideMethod?: boolean; - - /** - * By default, exported identifiers must refer to a declared variable. - * Set this to true to allow export statements to reference undeclared variables. - */ - allowUndeclaredExports?: boolean; - - /** - * Indicate the mode the code should be parsed in. - * Can be one of "script", "module", or "unambiguous". Defaults to "script". - * "unambiguous" will make @babel/parser attempt to guess, based on the presence - * of ES6 import or export statements. - * Files with ES6 imports and exports are considered "module" and are otherwise "script". - */ - sourceType?: 'script' | 'module' | 'unambiguous'; - - /** - * Correlate output AST nodes with their source filename. - * Useful when generating code and source maps from the ASTs of multiple input files. - */ - sourceFilename?: string; - - /** - * By default, the first line of code parsed is treated as line 1. - * You can provide a line number to alternatively start with. - * Useful for integration with other source tools. - */ - startLine?: number; - - /** - * Array containing the plugins that you want to enable. - */ - plugins?: ParserPlugin[]; - - /** - * Should the parser work in strict mode. - * Defaults to true if sourceType === 'module'. Otherwise, false. - */ - strictMode?: boolean; - - /** - * Adds a ranges property to each node: [node.start, node.end] - */ - ranges?: boolean; - - /** - * Adds all parsed tokens to a tokens property on the File node. - */ - tokens?: boolean; - - /** - * By default, the parser adds information about parentheses by setting - * `extra.parenthesized` to `true` as needed. - * When this option is `true` the parser creates `ParenthesizedExpression` - * AST nodes instead of using the `extra` property. - */ - createParenthesizedExpressions?: boolean; + /** + * By default, import and export declarations can only appear at a program's top level. + * Setting this option to true allows them anywhere where a statement is allowed. + */ + allowImportExportEverywhere?: boolean; + + /** + * By default, await use is not allowed outside of an async function. + * Set this to true to accept such code. + */ + allowAwaitOutsideFunction?: boolean; + + /** + * By default, a return statement at the top level raises an error. + * Set this to true to accept such code. + */ + allowReturnOutsideFunction?: boolean; + + allowSuperOutsideMethod?: boolean; + + /** + * By default, exported identifiers must refer to a declared variable. + * Set this to true to allow export statements to reference undeclared variables. + */ + allowUndeclaredExports?: boolean; + + /** + * Indicate the mode the code should be parsed in. + * Can be one of "script", "module", or "unambiguous". Defaults to "script". + * "unambiguous" will make @babel/parser attempt to guess, based on the presence + * of ES6 import or export statements. + * Files with ES6 imports and exports are considered "module" and are otherwise "script". + */ + sourceType?: "script" | "module" | "unambiguous"; + + /** + * Correlate output AST nodes with their source filename. + * Useful when generating code and source maps from the ASTs of multiple input files. + */ + sourceFilename?: string; + + /** + * By default, the first line of code parsed is treated as line 1. + * You can provide a line number to alternatively start with. + * Useful for integration with other source tools. + */ + startLine?: number; + + /** + * Array containing the plugins that you want to enable. + */ + plugins?: ParserPlugin[]; + + /** + * Should the parser work in strict mode. + * Defaults to true if sourceType === 'module'. Otherwise, false. + */ + strictMode?: boolean; + + /** + * Adds a ranges property to each node: [node.start, node.end] + */ + ranges?: boolean; + + /** + * Adds all parsed tokens to a tokens property on the File node. + */ + tokens?: boolean; + + /** + * By default, the parser adds information about parentheses by setting + * `extra.parenthesized` to `true` as needed. + * When this option is `true` the parser creates `ParenthesizedExpression` + * AST nodes instead of using the `extra` property. + */ + createParenthesizedExpressions?: boolean; } export type ParserPlugin = - 'asyncGenerators' | - 'bigInt' | - 'classPrivateMethods' | - 'classPrivateProperties' | - 'classProperties' | - 'decorators' | - 'decorators-legacy' | - 'doExpressions' | - 'dynamicImport' | - 'estree' | - 'exportDefaultFrom' | - 'exportNamespaceFrom' | - 'flow' | - 'flowComments' | - 'functionBind' | - 'functionSent' | - 'importMeta' | - 'jsx' | - 'logicalAssignment' | - 'nullishCoalescingOperator' | - 'numericSeparator' | - 'objectRestSpread' | - 'optionalCatchBinding' | - 'optionalChaining' | - 'partialApplication' | - 'pipelineOperator' | - 'placeholders' | - 'throwExpressions' | - 'typescript' | - ParserPluginWithOptions; + | "asyncGenerators" + | "bigInt" + | "classPrivateMethods" + | "classPrivateProperties" + | "classProperties" + | "decorators" + | "decorators-legacy" + | "doExpressions" + | "dynamicImport" + | "estree" + | "exportDefaultFrom" + | "exportNamespaceFrom" + | "flow" + | "flowComments" + | "functionBind" + | "functionSent" + | "importMeta" + | "jsx" + | "logicalAssignment" + | "nullishCoalescingOperator" + | "numericSeparator" + | "objectRestSpread" + | "optionalCatchBinding" + | "optionalChaining" + | "partialApplication" + | "pipelineOperator" + | "placeholders" + | "staticDecorators" + | "throwExpressions" + | "typescript" + | ParserPluginWithOptions; export type ParserPluginWithOptions = - ['decorators', DecoratorsPluginOptions] | - ['pipelineOperator', PipelineOperatorPluginOptions] | - ['flow', FlowPluginOptions]; + | ["decorators", DecoratorsPluginOptions] + | ["pipelineOperator", PipelineOperatorPluginOptions] + | ["flow", FlowPluginOptions]; export interface DecoratorsPluginOptions { - decoratorsBeforeExport?: boolean; + decoratorsBeforeExport?: boolean; } export interface PipelineOperatorPluginOptions { - proposal: 'minimal' | 'smart'; + proposal: "minimal" | "smart"; } export interface FlowPluginOptions { - all?: boolean; + all?: boolean; }