diff --git a/.gitignore b/.gitignore index 90283a241b..4dfb35cc7a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build coverage lib node_modules +npm-debug.log diff --git a/src/parser/statement.js b/src/parser/statement.js index 08885a009c..f4bd38fb2f 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -810,7 +810,8 @@ pp.parseClassSuper = function (node) { // Parses module export declaration. pp.parseExport = function (node) { - this.next(); + this.eat(tt._export); + // export * from '...' if (this.match(tt.star)) { const specifier = this.startNode(); diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 2eed420119..3d55c4e7a3 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -105,7 +105,7 @@ pp.flowParseDeclareFunction = function (node) { return this.finishNode(node, "DeclareFunction"); }; -pp.flowParseDeclare = function (node) { +pp.flowParseDeclare = function (node, insideModule) { if (this.match(tt._class)) { return this.flowParseDeclareClass(node); } else if (this.match(tt._function)) { @@ -116,12 +116,15 @@ pp.flowParseDeclare = function (node) { if (this.lookahead().type === tt.dot) { return this.flowParseDeclareModuleExports(node); } else { + if (insideModule) this.unexpected(null, "`declare module` cannot be used inside another `declare module`"); return this.flowParseDeclareModule(node); } } else if (this.isContextual("type")) { return this.flowParseDeclareTypeAlias(node); } else if (this.isContextual("interface")) { return this.flowParseDeclareInterface(node); + } else if (this.match(tt._export)) { + return this.flowParseDeclareExportDeclaration(node, insideModule); } else { this.unexpected(); } @@ -134,6 +137,17 @@ pp.flowParseDeclareVariable = function (node) { return this.finishNode(node, "DeclareVariable"); }; +function isEsModuleType(bodyElement) { + return bodyElement.type === "DeclareExportAllDeclaration" || + ( + bodyElement.type === "DeclareExportDeclaration" && + ( + !bodyElement.declaration || + (bodyElement.declaration.type !== "TypeAlias" && bodyElement.declaration.type !== "InterfaceDeclaration") + ) + ); +} + pp.flowParseDeclareModule = function (node) { this.next(); @@ -167,9 +181,94 @@ pp.flowParseDeclareModule = function (node) { this.expect(tt.braceR); this.finishNode(bodyNode, "BlockStatement"); + + let kind = null; + let hasModuleExport = false; + const errorMessage = "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module"; + body.forEach((bodyElement) => { + if (isEsModuleType(bodyElement)) { + if (kind === "CommonJS") this.unexpected(bodyElement.start, errorMessage); + kind = "ES"; + } else if (bodyElement.type === "DeclareModuleExports") { + if (hasModuleExport) this.unexpected(bodyElement.start, "Duplicate `declare module.exports` statement"); + if (kind === "ES") this.unexpected(bodyElement.start, errorMessage); + kind = "CommonJS"; + hasModuleExport = true; + } + }); + + node.kind = kind || "CommonJS"; return this.finishNode(node, "DeclareModule"); }; +const exportSuggestions = { + const: "declare export var", + let: "declare export var", + type: "export type", + interface: "export interface", +}; + +pp.flowParseDeclareExportDeclaration = function (node, insideModule) { + this.expect(tt._export); + + if (this.eat(tt._default)) { + if (this.match(tt._function) || this.match(tt._class)) { + // declare export default class ... + // declare export default function ... + node.declaration = this.flowParseDeclare(this.startNode()); + } else { + // declare export default [type]; + node.declaration = this.flowParseType(); + this.semicolon(); + } + node.default = true; + + return this.finishNode(node, "DeclareExportDeclaration"); + } else { + if ( + this.match(tt._const) || this.match(tt._let) || + ( + (this.isContextual("type") || this.isContextual("interface")) && + !insideModule + ) + ) { + const label = this.state.value; + const suggestion = exportSuggestions[label]; + this.unexpected(this.state.start, `\`declare export ${label}\` is not supported. Use \`${suggestion}\` instead`); + } + + if ( + this.match(tt._var) || // declare export var ... + this.match(tt._function) || // declare export function ... + this.match(tt._class) // declare export class ... + ) { + node.declaration = this.flowParseDeclare(this.startNode()); + node.default = false; + + return this.finishNode(node, "DeclareExportDeclaration"); + } else if ( + this.match(tt.star) || // declare export * from '' + this.match(tt.braceL) || // declare export {} ... + this.isContextual("interface") || // declare export interface ... + this.isContextual("type") // declare export type ... + ) { + node = this.parseExport(node); + if (node.type === "ExportNamedDeclaration") { + // flow does not support the ExportNamedDeclaration + node.type = "ExportDeclaration"; + node.default = false; + delete node.exportKind; + } + + node.type = "Declare" + node.type; + + return node; + } + } + + this.unexpected(); +}; + pp.flowParseDeclareModuleExports = function (node) { this.expectContextual("module"); this.expect(tt.dot); @@ -381,15 +480,6 @@ pp.flowParseObjectTypeMethodish = function (node) { return this.finishNode(node, "FunctionTypeAnnotation"); }; -pp.flowParseObjectTypeMethod = function (startPos, startLoc, isStatic, key) { - const node = this.startNodeAt(startPos, startLoc); - node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(startPos, startLoc)); - node.static = isStatic; - node.key = key; - node.optional = false; - return this.finishNode(node, "ObjectTypeProperty"); -}; - pp.flowParseObjectTypeCallProperty = function (node, isStatic) { const valueNode = this.startNode(); node.static = isStatic; @@ -402,9 +492,6 @@ pp.flowParseObjectType = function (allowStatic, allowExact, allowSpread) { this.state.inType = true; const nodeStart = this.startNode(); - let node; - let propertyKey; - let isStatic = false; nodeStart.callProperties = []; nodeStart.properties = []; @@ -425,10 +512,8 @@ pp.flowParseObjectType = function (allowStatic, allowExact, allowSpread) { nodeStart.exact = exact; while (!this.match(endDelim)) { - let optional = false; - const startPos = this.state.start; - const startLoc = this.state.startLoc; - node = this.startNode(); + let isStatic = false; + const node = this.startNode(); if (allowStatic && this.isContextual("static") && this.lookahead().type !== tt.colon) { this.next(); isStatic = true; @@ -444,44 +529,24 @@ pp.flowParseObjectType = function (allowStatic, allowExact, allowSpread) { } nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic)); } else { - if (this.match(tt.ellipsis)) { - if (!allowSpread) { - this.unexpected( - null, - "Spread operator cannot appear in class or interface definitions" - ); - } - if (variance) { - this.unexpected(variance.start, "Spread properties cannot have variance"); - } - this.expect(tt.ellipsis); - node.argument = this.flowParseType(); - nodeStart.properties.push(this.finishNode(node, "ObjectTypeSpreadProperty")); - } else { - propertyKey = this.flowParseObjectPropertyKey(); - if (this.isRelational("<") || this.match(tt.parenL)) { - // This is a method property - if (variance) { - this.unexpected(variance.start); - } - nodeStart.properties.push(this.flowParseObjectTypeMethod(startPos, startLoc, isStatic, propertyKey)); - } else { - if (this.eat(tt.question)) { - optional = true; - } - node.key = propertyKey; - node.value = this.flowParseTypeInitialiser(); - node.optional = optional; - node.static = isStatic; - node.variance = variance; - nodeStart.properties.push(this.finishNode(node, "ObjectTypeProperty")); + let kind = "init"; + + if (this.isContextual("get") || this.isContextual("set")) { + const lookahead = this.lookahead(); + if ( + lookahead.type === tt.name || + lookahead.type === tt.string || + lookahead.type === tt.num + ) { + kind = this.state.value; + this.next(); } } + + nodeStart.properties.push(this.flowParseObjectTypeProperty(node, isStatic, variance, kind, allowSpread)); } this.flowObjectTypeSemicolon(); - - isStatic = false; } this.expect(endDelim); @@ -493,6 +558,65 @@ pp.flowParseObjectType = function (allowStatic, allowExact, allowSpread) { return out; }; +pp.flowParseObjectTypeProperty = function (node, isStatic, variance, kind, allowSpread) { + if (this.match(tt.ellipsis)) { + if (!allowSpread) { + this.unexpected( + null, + "Spread operator cannot appear in class or interface definitions" + ); + } + if (variance) { + this.unexpected(variance.start, "Spread properties cannot have variance"); + } + this.expect(tt.ellipsis); + node.argument = this.flowParseType(); + + return this.finishNode(node, "ObjectTypeSpreadProperty"); + } else { + node.key = this.flowParseObjectPropertyKey(); + node.static = isStatic; + node.kind = kind; + + let optional = false; + if (this.isRelational("<") || this.match(tt.parenL)) { + // This is a method property + if (variance) { + this.unexpected(variance.start); + } + + node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.start, node.loc.start)); + if (kind === "get" || kind === "set") this.flowCheckGetterSetterParamCount(node); + } else { + if (kind !== "init") this.unexpected(); + if (this.eat(tt.question)) { + optional = true; + } + node.value = this.flowParseTypeInitialiser(); + node.variance = variance; + + } + + node.optional = optional; + + return this.finishNode(node, "ObjectTypeProperty"); + } +}; + +// This is similar to checkGetterSetterParamCount, but as +// babylon uses non estree properties we cannot reuse it here +pp.flowCheckGetterSetterParamCount = function (property) { + const paramCount = property.kind === "get" ? 0 : 1; + if (property.value.params.length !== paramCount) { + const start = property.start; + if (property.kind === "get") { + this.raise(start, "getter should have no params"); + } else { + this.raise(start, "setter should have exactly one param"); + } + } +}; + pp.flowObjectTypeSemicolon = function () { if (!this.eat(tt.semi) && !this.eat(tt.comma) && !this.match(tt.braceR) && !this.match(tt.braceBarR)) { @@ -898,7 +1022,7 @@ export default (superClass) => class extends superClass { parseExpressionStatement(node, expr) { if (expr.type === "Identifier") { if (expr.name === "declare") { - if (this.match(tt._class) || this.match(tt.name) || this.match(tt._function) || this.match(tt._var)) { + if (this.match(tt._class) || this.match(tt.name) || this.match(tt._function) || this.match(tt._var) || this.match(tt._export)) { return this.flowParseDeclare(node); } } else if (this.match(tt.name)) { diff --git a/test/fixtures/flow/call-properties/3/expected.json b/test/fixtures/flow/call-properties/3/expected.json index d5d5d6599e..acd2bf6782 100644 --- a/test/fixtures/flow/call-properties/3/expected.json +++ b/test/fixtures/flow/call-properties/3/expected.json @@ -282,6 +282,8 @@ }, "name": "y" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 25, @@ -297,9 +299,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/class-properties/getter-setter/actual.js b/test/fixtures/flow/class-properties/getter-setter/actual.js new file mode 100644 index 0000000000..7a6fc4985b --- /dev/null +++ b/test/fixtures/flow/class-properties/getter-setter/actual.js @@ -0,0 +1,8 @@ +declare class B { + get a(): number; + set b(a: number): void; + get "c"(): number; + set "d"(a: number): void; + get 1(): number; + set 2(a: number): void; +} diff --git a/test/fixtures/flow/class-properties/getter-setter/expected.json b/test/fixtures/flow/class-properties/getter-setter/expected.json new file mode 100644 index 0000000000..13744ddb93 --- /dev/null +++ b/test/fixtures/flow/class-properties/getter-setter/expected.json @@ -0,0 +1,656 @@ +{ + "type": "File", + "start": 0, + "end": 158, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 158, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareClass", + "start": 0, + "end": 158, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "B" + }, + "name": "B" + }, + "typeParameters": null, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 16, + "end": 158, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 20, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "key": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "static": false, + "kind": "get", + "value": { + "type": "FunctionTypeAnnotation", + "start": 20, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "params": [], + "rest": null, + "typeParameters": null, + "returnType": { + "type": "NumberTypeAnnotation", + "start": 29, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 17 + } + } + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 39, + "end": 61, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "key": { + "type": "Identifier", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + }, + "static": false, + "kind": "set", + "value": { + "type": "FunctionTypeAnnotation", + "start": 39, + "end": 61, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "params": [ + { + "type": "FunctionTypeParam", + "start": 45, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + }, + "identifierName": "a" + }, + "name": "a" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 48, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 17 + } + } + } + } + ], + "rest": null, + "typeParameters": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 57, + "end": 61, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 24 + } + } + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 65, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "key": { + "type": "StringLiteral", + "start": 69, + "end": 72, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "extra": { + "rawValue": "c", + "raw": "\"c\"" + }, + "value": "c" + }, + "static": false, + "kind": "get", + "value": { + "type": "FunctionTypeAnnotation", + "start": 65, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "params": [], + "rest": null, + "typeParameters": null, + "returnType": { + "type": "NumberTypeAnnotation", + "start": 76, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 19 + } + } + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 86, + "end": 110, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "key": { + "type": "StringLiteral", + "start": 90, + "end": 93, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "extra": { + "rawValue": "d", + "raw": "\"d\"" + }, + "value": "d" + }, + "static": false, + "kind": "set", + "value": { + "type": "FunctionTypeAnnotation", + "start": 86, + "end": 110, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "params": [ + { + "type": "FunctionTypeParam", + "start": 94, + "end": 103, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "name": { + "type": "Identifier", + "start": 94, + "end": 95, + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + }, + "identifierName": "a" + }, + "name": "a" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 97, + "end": 103, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + } + ], + "rest": null, + "typeParameters": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 106, + "end": 110, + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 26 + } + } + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 114, + "end": 129, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "key": { + "type": "NumericLiteral", + "start": 118, + "end": 119, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "static": false, + "kind": "get", + "value": { + "type": "FunctionTypeAnnotation", + "start": 114, + "end": 129, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "params": [], + "rest": null, + "typeParameters": null, + "returnType": { + "type": "NumberTypeAnnotation", + "start": 123, + "end": 129, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 17 + } + } + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 133, + "end": 155, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 24 + } + }, + "key": { + "type": "NumericLiteral", + "start": 137, + "end": 138, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + "static": false, + "kind": "set", + "value": { + "type": "FunctionTypeAnnotation", + "start": 133, + "end": 155, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 24 + } + }, + "params": [ + { + "type": "FunctionTypeParam", + "start": 139, + "end": 148, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 139, + "end": 140, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + }, + "identifierName": "a" + }, + "name": "a" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 142, + "end": 148, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 17 + } + } + } + } + ], + "rest": null, + "typeParameters": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 151, + "end": 155, + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 24 + } + } + } + }, + "optional": false + } + ], + "indexers": [], + "exact": false + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/class-properties/invalid-getter-setter/actual.js b/test/fixtures/flow/class-properties/invalid-getter-setter/actual.js new file mode 100644 index 0000000000..0cc1b7fa51 --- /dev/null +++ b/test/fixtures/flow/class-properties/invalid-getter-setter/actual.js @@ -0,0 +1,3 @@ +declare class B { + get a: number; +} diff --git a/test/fixtures/flow/class-properties/invalid-getter-setter/options.json b/test/fixtures/flow/class-properties/invalid-getter-setter/options.json new file mode 100644 index 0000000000..4e84114247 --- /dev/null +++ b/test/fixtures/flow/class-properties/invalid-getter-setter/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:7)" +} diff --git a/test/fixtures/flow/class-properties/invalid-named-static/expected.json b/test/fixtures/flow/class-properties/invalid-named-static/expected.json new file mode 100644 index 0000000000..016fc254c0 --- /dev/null +++ b/test/fixtures/flow/class-properties/invalid-named-static/expected.json @@ -0,0 +1,33 @@ +{ + "type": "File", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "sourceType": "module", + "body": [], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/class-properties/named-static/expected.json b/test/fixtures/flow/class-properties/named-static/expected.json index 61bf3d6674..eea8e7d6a6 100644 --- a/test/fixtures/flow/class-properties/named-static/expected.json +++ b/test/fixtures/flow/class-properties/named-static/expected.json @@ -109,6 +109,8 @@ }, "name": "static" }, + "static": false, + "kind": "init", "value": { "type": "GenericTypeAnnotation", "start": 28, @@ -142,9 +144,8 @@ "name": "T" } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/declare-export/export-class/actual.js b/test/fixtures/flow/declare-export/export-class/actual.js new file mode 100644 index 0000000000..07165a036a --- /dev/null +++ b/test/fixtures/flow/declare-export/export-class/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export class Foo { meth(p1: number): void; } } diff --git a/test/fixtures/flow/declare-export/export-class/expected.json b/test/fixtures/flow/declare-export/export-class/expected.json new file mode 100644 index 0000000000..d403da0296 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-class/expected.json @@ -0,0 +1,275 @@ +{ + "type": "File", + "start": 0, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 77 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 77 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 77 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 77 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 75, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 75 + } + }, + "declaration": { + "type": "DeclareClass", + "start": 38, + "end": 75, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 75 + } + }, + "id": { + "type": "Identifier", + "start": 44, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 1, + "column": 47 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "typeParameters": null, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 48, + "end": 75, + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 75 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 50, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 50 + }, + "end": { + "line": 1, + "column": 72 + } + }, + "key": { + "type": "Identifier", + "start": 50, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 50 + }, + "end": { + "line": 1, + "column": 54 + }, + "identifierName": "meth" + }, + "name": "meth" + }, + "static": false, + "kind": "init", + "value": { + "type": "FunctionTypeAnnotation", + "start": 50, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 50 + }, + "end": { + "line": 1, + "column": 72 + } + }, + "params": [ + { + "type": "FunctionTypeParam", + "start": 55, + "end": 65, + "loc": { + "start": { + "line": 1, + "column": 55 + }, + "end": { + "line": 1, + "column": 65 + } + }, + "name": { + "type": "Identifier", + "start": 55, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 55 + }, + "end": { + "line": 1, + "column": 57 + }, + "identifierName": "p1" + }, + "name": "p1" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 59, + "end": 65, + "loc": { + "start": { + "line": 1, + "column": 59 + }, + "end": { + "line": 1, + "column": 65 + } + } + } + } + ], + "rest": null, + "typeParameters": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 68, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 68 + }, + "end": { + "line": 1, + "column": 72 + } + } + } + }, + "optional": false + } + ], + "indexers": [], + "exact": false + } + }, + "default": false + } + ] + }, + "kind": "ES" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-default-arrow/actual.js b/test/fixtures/flow/declare-export/export-default-arrow/actual.js new file mode 100644 index 0000000000..f6ae0263aa --- /dev/null +++ b/test/fixtures/flow/declare-export/export-default-arrow/actual.js @@ -0,0 +1 @@ +declare export default (a:number) => number diff --git a/test/fixtures/flow/declare-export/export-default-arrow/expected.json b/test/fixtures/flow/declare-export/export-default-arrow/expected.json new file mode 100644 index 0000000000..cd5ff0a411 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-default-arrow/expected.json @@ -0,0 +1,132 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "declaration": { + "type": "FunctionTypeAnnotation", + "start": 23, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "params": [ + { + "type": "FunctionTypeParam", + "start": 24, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "name": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "a" + }, + "name": "a" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 32 + } + } + } + } + ], + "rest": null, + "returnType": { + "type": "NumberTypeAnnotation", + "start": 37, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 43 + } + } + }, + "typeParameters": null + }, + "default": true + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-default-class/actual.js b/test/fixtures/flow/declare-export/export-default-class/actual.js new file mode 100644 index 0000000000..c26ec8d304 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-default-class/actual.js @@ -0,0 +1 @@ +declare export default class A {}; diff --git a/test/fixtures/flow/declare-export/export-default-class/expected.json b/test/fixtures/flow/declare-export/export-default-class/expected.json new file mode 100644 index 0000000000..62d258e3a7 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-default-class/expected.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "declaration": { + "type": "DeclareClass", + "start": 23, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "A" + }, + "name": "A" + }, + "typeParameters": null, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "exact": false + } + }, + "default": true + }, + { + "type": "EmptyStatement", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-default-function/actual.js b/test/fixtures/flow/declare-export/export-default-function/actual.js new file mode 100644 index 0000000000..7f28065f5c --- /dev/null +++ b/test/fixtures/flow/declare-export/export-default-function/actual.js @@ -0,0 +1 @@ +declare export default function bar(p1: number): string; diff --git a/test/fixtures/flow/declare-export/export-default-function/expected.json b/test/fixtures/flow/declare-export/export-default-function/expected.json new file mode 100644 index 0000000000..b433681f6b --- /dev/null +++ b/test/fixtures/flow/declare-export/export-default-function/expected.json @@ -0,0 +1,180 @@ +{ + "type": "File", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "declaration": { + "type": "DeclareFunction", + "start": 23, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "id": { + "type": "Identifier", + "start": 32, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 55 + }, + "identifierName": "bar" + }, + "name": "bar", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 35, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 55 + } + }, + "typeAnnotation": { + "type": "FunctionTypeAnnotation", + "start": 35, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 55 + } + }, + "typeParameters": null, + "params": [ + { + "type": "FunctionTypeParam", + "start": 36, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "name": { + "type": "Identifier", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 38 + }, + "identifierName": "p1" + }, + "name": "p1" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 40, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 46 + } + } + } + } + ], + "rest": null, + "returnType": { + "type": "StringTypeAnnotation", + "start": 49, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 49 + }, + "end": { + "line": 1, + "column": 55 + } + } + } + } + } + }, + "predicate": null + }, + "default": true + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-default-union/actual.js b/test/fixtures/flow/declare-export/export-default-union/actual.js new file mode 100644 index 0000000000..ec6a2fb669 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-default-union/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export default number|string; } \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-default-union/expected.json b/test/fixtures/flow/declare-export/export-default-union/expected.json new file mode 100644 index 0000000000..331f6890a2 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-default-union/expected.json @@ -0,0 +1,150 @@ +{ + "type": "File", + "start": 0, + "end": 62, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 62 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 62, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 62 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 62, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 62 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 62, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 62 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 60, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 60 + } + }, + "declaration": { + "type": "UnionTypeAnnotation", + "start": 46, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 46 + }, + "end": { + "line": 1, + "column": 59 + } + }, + "types": [ + { + "type": "NumberTypeAnnotation", + "start": 46, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 46 + }, + "end": { + "line": 1, + "column": 52 + } + } + }, + { + "type": "StringTypeAnnotation", + "start": 53, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 53 + }, + "end": { + "line": 1, + "column": 59 + } + } + } + ] + }, + "default": true + } + ] + }, + "kind": "ES" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-from/actual.js b/test/fixtures/flow/declare-export/export-from/actual.js new file mode 100644 index 0000000000..516e8e2100 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-from/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export {a,} from "bar"; } diff --git a/test/fixtures/flow/declare-export/export-from/expected.json b/test/fixtures/flow/declare-export/export-from/expected.json new file mode 100644 index 0000000000..6fde07ca48 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-from/expected.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "declaration": null, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "local": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + }, + "identifierName": "a" + }, + "name": "a" + }, + "exported": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + }, + "identifierName": "a" + }, + "name": "a" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 48, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 53 + } + }, + "extra": { + "rawValue": "bar", + "raw": "\"bar\"" + }, + "value": "bar" + }, + "default": false + } + ] + }, + "kind": "ES" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-function/actual.js b/test/fixtures/flow/declare-export/export-function/actual.js new file mode 100644 index 0000000000..4b0b254fe4 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-function/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export function bar(p1: number): string; } diff --git a/test/fixtures/flow/declare-export/export-function/expected.json b/test/fixtures/flow/declare-export/export-function/expected.json new file mode 100644 index 0000000000..79377de65a --- /dev/null +++ b/test/fixtures/flow/declare-export/export-function/expected.json @@ -0,0 +1,233 @@ +{ + "type": "File", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 71, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 71 + } + }, + "declaration": { + "type": "DeclareFunction", + "start": 38, + "end": 71, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 71 + } + }, + "id": { + "type": "Identifier", + "start": 47, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 47 + }, + "end": { + "line": 1, + "column": 70 + }, + "identifierName": "bar" + }, + "name": "bar", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 50, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 50 + }, + "end": { + "line": 1, + "column": 70 + } + }, + "typeAnnotation": { + "type": "FunctionTypeAnnotation", + "start": 50, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 50 + }, + "end": { + "line": 1, + "column": 70 + } + }, + "typeParameters": null, + "params": [ + { + "type": "FunctionTypeParam", + "start": 51, + "end": 61, + "loc": { + "start": { + "line": 1, + "column": 51 + }, + "end": { + "line": 1, + "column": 61 + } + }, + "name": { + "type": "Identifier", + "start": 51, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 51 + }, + "end": { + "line": 1, + "column": 53 + }, + "identifierName": "p1" + }, + "name": "p1" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 55, + "end": 61, + "loc": { + "start": { + "line": 1, + "column": 55 + }, + "end": { + "line": 1, + "column": 61 + } + } + } + } + ], + "rest": null, + "returnType": { + "type": "StringTypeAnnotation", + "start": 64, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 64 + }, + "end": { + "line": 1, + "column": 70 + } + } + } + } + } + }, + "predicate": null + }, + "default": false + } + ] + }, + "kind": "ES" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-interface-and-var/actual.js b/test/fixtures/flow/declare-export/export-interface-and-var/actual.js new file mode 100644 index 0000000000..2f9a87e3ad --- /dev/null +++ b/test/fixtures/flow/declare-export/export-interface-and-var/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export interface bar {} declare export var baz: number; } diff --git a/test/fixtures/flow/declare-export/export-interface-and-var/expected.json b/test/fixtures/flow/declare-export/export-interface-and-var/expected.json new file mode 100644 index 0000000000..c793dc2bb5 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-interface-and-var/expected.json @@ -0,0 +1,237 @@ +{ + "type": "File", + "start": 0, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "InterfaceDeclaration", + "start": 38, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "id": { + "type": "Identifier", + "start": 48, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 51 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "typeParameters": null, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 52, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 52 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "exact": false + } + }, + "default": false + }, + { + "type": "DeclareExportDeclaration", + "start": 55, + "end": 86, + "loc": { + "start": { + "line": 1, + "column": 55 + }, + "end": { + "line": 1, + "column": 86 + } + }, + "declaration": { + "type": "DeclareVariable", + "start": 70, + "end": 86, + "loc": { + "start": { + "line": 1, + "column": 70 + }, + "end": { + "line": 1, + "column": 86 + } + }, + "id": { + "type": "Identifier", + "start": 74, + "end": 85, + "loc": { + "start": { + "line": 1, + "column": 74 + }, + "end": { + "line": 1, + "column": 85 + }, + "identifierName": "baz" + }, + "name": "baz", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 77, + "end": 85, + "loc": { + "start": { + "line": 1, + "column": 77 + }, + "end": { + "line": 1, + "column": 85 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 79, + "end": 85, + "loc": { + "start": { + "line": 1, + "column": 79 + }, + "end": { + "line": 1, + "column": 85 + } + } + } + } + } + }, + "default": false + } + ] + }, + "kind": "ES" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-interface-commonjs/actual.js b/test/fixtures/flow/declare-export/export-interface-commonjs/actual.js new file mode 100644 index 0000000000..d624036826 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-interface-commonjs/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export interface bar {} declare module.exports: number; } diff --git a/test/fixtures/flow/declare-export/export-interface-commonjs/expected.json b/test/fixtures/flow/declare-export/export-interface-commonjs/expected.json new file mode 100644 index 0000000000..9263cc2989 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-interface-commonjs/expected.json @@ -0,0 +1,204 @@ +{ + "type": "File", + "start": 0, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "InterfaceDeclaration", + "start": 38, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "id": { + "type": "Identifier", + "start": 48, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 51 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "typeParameters": null, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 52, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 52 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "exact": false + } + }, + "default": false + }, + { + "type": "DeclareModuleExports", + "start": 55, + "end": 86, + "loc": { + "start": { + "line": 1, + "column": 55 + }, + "end": { + "line": 1, + "column": 86 + } + }, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 77, + "end": 85, + "loc": { + "start": { + "line": 1, + "column": 77 + }, + "end": { + "line": 1, + "column": 85 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 79, + "end": 85, + "loc": { + "start": { + "line": 1, + "column": 79 + }, + "end": { + "line": 1, + "column": 85 + } + } + } + } + } + ] + }, + "kind": "CommonJS" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-interface/actual.js b/test/fixtures/flow/declare-export/export-interface/actual.js new file mode 100644 index 0000000000..29047342e2 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-interface/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export interface bar {} } diff --git a/test/fixtures/flow/declare-export/export-interface/expected.json b/test/fixtures/flow/declare-export/export-interface/expected.json new file mode 100644 index 0000000000..2524845b73 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-interface/expected.json @@ -0,0 +1,159 @@ +{ + "type": "File", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "InterfaceDeclaration", + "start": 38, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "id": { + "type": "Identifier", + "start": 48, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 51 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "typeParameters": null, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 52, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 52 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "exact": false + } + }, + "default": false + } + ] + }, + "kind": "CommonJS" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-named-pattern/actual.js b/test/fixtures/flow/declare-export/export-named-pattern/actual.js new file mode 100644 index 0000000000..6a25a18365 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-named-pattern/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export {a,}; } diff --git a/test/fixtures/flow/declare-export/export-named-pattern/expected.json b/test/fixtures/flow/declare-export/export-named-pattern/expected.json new file mode 100644 index 0000000000..6e1791ff95 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-named-pattern/expected.json @@ -0,0 +1,156 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "declaration": null, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "local": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + }, + "identifierName": "a" + }, + "name": "a" + }, + "exported": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + }, + "identifierName": "a" + }, + "name": "a" + } + } + ], + "source": null, + "default": false + } + ] + }, + "kind": "ES" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-star-as/actual.js b/test/fixtures/flow/declare-export/export-star-as/actual.js new file mode 100644 index 0000000000..3f0c9ebabf --- /dev/null +++ b/test/fixtures/flow/declare-export/export-star-as/actual.js @@ -0,0 +1 @@ +declare export * as test from '' diff --git a/test/fixtures/flow/declare-export/export-star-as/expected.json b/test/fixtures/flow/declare-export/export-star-as/expected.json new file mode 100644 index 0000000000..ecf6deda99 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-star-as/expected.json @@ -0,0 +1,104 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "specifiers": [ + { + "type": "ExportNamespaceSpecifier", + "start": 15, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "exported": { + "type": "Identifier", + "start": 20, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "test" + }, + "name": "test" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 30, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "extra": { + "rawValue": "", + "raw": "''" + }, + "value": "" + }, + "default": false + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-star-as/options.json b/test/fixtures/flow/declare-export/export-star-as/options.json new file mode 100644 index 0000000000..edcc382322 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-star-as/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["exportExtensions"] +} diff --git a/test/fixtures/flow/declare-export/export-star/actual.js b/test/fixtures/flow/declare-export/export-star/actual.js new file mode 100644 index 0000000000..25be792a09 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-star/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export * from "bar"; } diff --git a/test/fixtures/flow/declare-export/export-star/expected.json b/test/fixtures/flow/declare-export/export-star/expected.json new file mode 100644 index 0000000000..16df6ff122 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-star/expected.json @@ -0,0 +1,122 @@ +{ + "type": "File", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 53 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 53 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 53 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 53 + } + }, + "body": [ + { + "type": "DeclareExportAllDeclaration", + "start": 23, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "source": { + "type": "StringLiteral", + "start": 45, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "extra": { + "rawValue": "bar", + "raw": "\"bar\"" + }, + "value": "bar" + } + } + ] + }, + "kind": "ES" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-type-and-var/actual.js b/test/fixtures/flow/declare-export/export-type-and-var/actual.js new file mode 100644 index 0000000000..f4de1e146f --- /dev/null +++ b/test/fixtures/flow/declare-export/export-type-and-var/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export type bar = number; declare export var baz: number; } diff --git a/test/fixtures/flow/declare-export/export-type-and-var/expected.json b/test/fixtures/flow/declare-export/export-type-and-var/expected.json new file mode 100644 index 0000000000..1b6544a294 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-type-and-var/expected.json @@ -0,0 +1,231 @@ +{ + "type": "File", + "start": 0, + "end": 90, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 90 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 90, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 90 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 90, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 90 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 90, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 90 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "TypeAlias", + "start": 38, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "id": { + "type": "Identifier", + "start": 43, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 46 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "typeParameters": null, + "right": { + "type": "NumberTypeAnnotation", + "start": 49, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 49 + }, + "end": { + "line": 1, + "column": 55 + } + } + } + }, + "default": false + }, + { + "type": "DeclareExportDeclaration", + "start": 57, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 57 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "declaration": { + "type": "DeclareVariable", + "start": 72, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 72 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "id": { + "type": "Identifier", + "start": 76, + "end": 87, + "loc": { + "start": { + "line": 1, + "column": 76 + }, + "end": { + "line": 1, + "column": 87 + }, + "identifierName": "baz" + }, + "name": "baz", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 79, + "end": 87, + "loc": { + "start": { + "line": 1, + "column": 79 + }, + "end": { + "line": 1, + "column": 87 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 81, + "end": 87, + "loc": { + "start": { + "line": 1, + "column": 81 + }, + "end": { + "line": 1, + "column": 87 + } + } + } + } + } + }, + "default": false + } + ] + }, + "kind": "ES" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-type-commonjs/actual.js b/test/fixtures/flow/declare-export/export-type-commonjs/actual.js new file mode 100644 index 0000000000..21cd35d78d --- /dev/null +++ b/test/fixtures/flow/declare-export/export-type-commonjs/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export type bar = number; declare module.exports: number; } diff --git a/test/fixtures/flow/declare-export/export-type-commonjs/expected.json b/test/fixtures/flow/declare-export/export-type-commonjs/expected.json new file mode 100644 index 0000000000..c97883f7d0 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-type-commonjs/expected.json @@ -0,0 +1,198 @@ +{ + "type": "File", + "start": 0, + "end": 90, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 90 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 90, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 90 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 90, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 90 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 90, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 90 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "TypeAlias", + "start": 38, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "id": { + "type": "Identifier", + "start": 43, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 46 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "typeParameters": null, + "right": { + "type": "NumberTypeAnnotation", + "start": 49, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 49 + }, + "end": { + "line": 1, + "column": 55 + } + } + } + }, + "default": false + }, + { + "type": "DeclareModuleExports", + "start": 57, + "end": 88, + "loc": { + "start": { + "line": 1, + "column": 57 + }, + "end": { + "line": 1, + "column": 88 + } + }, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 79, + "end": 87, + "loc": { + "start": { + "line": 1, + "column": 79 + }, + "end": { + "line": 1, + "column": 87 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 81, + "end": 87, + "loc": { + "start": { + "line": 1, + "column": 81 + }, + "end": { + "line": 1, + "column": 87 + } + } + } + } + } + ] + }, + "kind": "CommonJS" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-type/actual.js b/test/fixtures/flow/declare-export/export-type/actual.js new file mode 100644 index 0000000000..422ea5547e --- /dev/null +++ b/test/fixtures/flow/declare-export/export-type/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export type bar = number; } diff --git a/test/fixtures/flow/declare-export/export-type/expected.json b/test/fixtures/flow/declare-export/export-type/expected.json new file mode 100644 index 0000000000..aa03bfa368 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-type/expected.json @@ -0,0 +1,153 @@ +{ + "type": "File", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 58 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 58 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 58 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 58 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "TypeAlias", + "start": 38, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "id": { + "type": "Identifier", + "start": 43, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 46 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "typeParameters": null, + "right": { + "type": "NumberTypeAnnotation", + "start": 49, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 49 + }, + "end": { + "line": 1, + "column": 55 + } + } + } + }, + "default": false + } + ] + }, + "kind": "CommonJS" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/export-var/actual.js b/test/fixtures/flow/declare-export/export-var/actual.js new file mode 100644 index 0000000000..b14a9dda53 --- /dev/null +++ b/test/fixtures/flow/declare-export/export-var/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export var a: number; } diff --git a/test/fixtures/flow/declare-export/export-var/expected.json b/test/fixtures/flow/declare-export/export-var/expected.json new file mode 100644 index 0000000000..d176ea111b --- /dev/null +++ b/test/fixtures/flow/declare-export/export-var/expected.json @@ -0,0 +1,165 @@ +{ + "type": "File", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "id": { + "type": "StringLiteral", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "body": [ + { + "type": "DeclareExportDeclaration", + "start": 23, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 52 + } + }, + "declaration": { + "type": "DeclareVariable", + "start": 38, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 52 + } + }, + "id": { + "type": "Identifier", + "start": 42, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 1, + "column": 51 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 43, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 45, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 51 + } + } + } + } + } + }, + "default": false + } + ] + }, + "kind": "ES" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-export/invalid-declare-export-type/actual.js b/test/fixtures/flow/declare-export/invalid-declare-export-type/actual.js new file mode 100644 index 0000000000..f2c105f061 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-declare-export-type/actual.js @@ -0,0 +1 @@ +declare export type foo = number; diff --git a/test/fixtures/flow/declare-export/invalid-declare-export-type/options.json b/test/fixtures/flow/declare-export/invalid-declare-export-type/options.json new file mode 100644 index 0000000000..2f2a34e735 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-declare-export-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "`declare export type` is not supported. Use `export type` instead (1:15)" +} diff --git a/test/fixtures/flow/declare-export/invalid-export-arrow/actual.js b/test/fixtures/flow/declare-export/invalid-export-arrow/actual.js new file mode 100644 index 0000000000..a5b27cf870 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-arrow/actual.js @@ -0,0 +1 @@ +declare export (a:number) => number diff --git a/test/fixtures/flow/declare-export/invalid-export-arrow/options.json b/test/fixtures/flow/declare-export/invalid-export-arrow/options.json new file mode 100644 index 0000000000..98d7123790 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-arrow/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:15)" +} diff --git a/test/fixtures/flow/declare-export/invalid-export-const/actual.js b/test/fixtures/flow/declare-export/invalid-export-const/actual.js new file mode 100644 index 0000000000..8ee799daa5 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-const/actual.js @@ -0,0 +1 @@ +declare export const foo: number diff --git a/test/fixtures/flow/declare-export/invalid-export-const/options.json b/test/fixtures/flow/declare-export/invalid-export-const/options.json new file mode 100644 index 0000000000..8466e2ca85 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-const/options.json @@ -0,0 +1,3 @@ +{ + "throws": "`declare export const` is not supported. Use `declare export var` instead (1:15)" +} diff --git a/test/fixtures/flow/declare-export/invalid-export-default-function/actual.js b/test/fixtures/flow/declare-export/invalid-export-default-function/actual.js new file mode 100644 index 0000000000..237a1224ad --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-default-function/actual.js @@ -0,0 +1 @@ +declare export default function (p1: number): string; diff --git a/test/fixtures/flow/declare-export/invalid-export-default-function/options.json b/test/fixtures/flow/declare-export/invalid-export-default-function/options.json new file mode 100644 index 0000000000..40981abf7e --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-default-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:32)" +} diff --git a/test/fixtures/flow/declare-export/invalid-export-default-var/actual.js b/test/fixtures/flow/declare-export/invalid-export-default-var/actual.js new file mode 100644 index 0000000000..c90458445b --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-default-var/actual.js @@ -0,0 +1 @@ +declare export default var a: number diff --git a/test/fixtures/flow/declare-export/invalid-export-default-var/options.json b/test/fixtures/flow/declare-export/invalid-export-default-var/options.json new file mode 100644 index 0000000000..562afcef48 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-default-var/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:23)" +} diff --git a/test/fixtures/flow/declare-export/invalid-export-interface/actual.js b/test/fixtures/flow/declare-export/invalid-export-interface/actual.js new file mode 100644 index 0000000000..aad1860f10 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-interface/actual.js @@ -0,0 +1 @@ +declare export interface bar {} diff --git a/test/fixtures/flow/declare-export/invalid-export-interface/options.json b/test/fixtures/flow/declare-export/invalid-export-interface/options.json new file mode 100644 index 0000000000..3977f3c480 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-interface/options.json @@ -0,0 +1,3 @@ +{ + "throws": "`declare export interface` is not supported. Use `export interface` instead (1:15)" +} diff --git a/test/fixtures/flow/declare-export/invalid-export-let/actual.js b/test/fixtures/flow/declare-export/invalid-export-let/actual.js new file mode 100644 index 0000000000..cffa3c63b6 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-let/actual.js @@ -0,0 +1 @@ +declare export let foo: number diff --git a/test/fixtures/flow/declare-export/invalid-export-let/options.json b/test/fixtures/flow/declare-export/invalid-export-let/options.json new file mode 100644 index 0000000000..745a711f11 --- /dev/null +++ b/test/fixtures/flow/declare-export/invalid-export-let/options.json @@ -0,0 +1,3 @@ +{ + "throws": "`declare export let` is not supported. Use `declare export var` instead (1:15)" +} diff --git a/test/fixtures/flow/declare-module/1/expected.json b/test/fixtures/flow/declare-module/1/expected.json index 543af8e16b..f209133694 100644 --- a/test/fixtures/flow/declare-module/1/expected.json +++ b/test/fixtures/flow/declare-module/1/expected.json @@ -74,7 +74,8 @@ } }, "body": [] - } + }, + "kind": "CommonJS" } ], "directives": [] diff --git a/test/fixtures/flow/declare-module/10/actual.js b/test/fixtures/flow/declare-module/10/actual.js new file mode 100644 index 0000000000..ccbf397e99 --- /dev/null +++ b/test/fixtures/flow/declare-module/10/actual.js @@ -0,0 +1 @@ +declare module.exports: { foo(): number; } diff --git a/test/fixtures/flow/declare-module/10/expected.json b/test/fixtures/flow/declare-module/10/expected.json new file mode 100644 index 0000000000..5b28d3a95c --- /dev/null +++ b/test/fixtures/flow/declare-module/10/expected.json @@ -0,0 +1,152 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareModuleExports", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 22, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "typeAnnotation": { + "type": "ObjectTypeAnnotation", + "start": 24, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 26, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "key": { + "type": "Identifier", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "static": false, + "kind": "init", + "value": { + "type": "FunctionTypeAnnotation", + "start": 26, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "params": [], + "rest": null, + "typeParameters": null, + "returnType": { + "type": "NumberTypeAnnotation", + "start": 33, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 39 + } + } + } + }, + "optional": false + } + ], + "indexers": [], + "exact": false + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/declare-module/2/expected.json b/test/fixtures/flow/declare-module/2/expected.json index 887e105b6e..8643e9feaa 100644 --- a/test/fixtures/flow/declare-module/2/expected.json +++ b/test/fixtures/flow/declare-module/2/expected.json @@ -77,7 +77,8 @@ } }, "body": [] - } + }, + "kind": "CommonJS" } ], "directives": [] diff --git a/test/fixtures/flow/declare-module/3/expected.json b/test/fixtures/flow/declare-module/3/expected.json index b390a8eba8..8e61c95762 100644 --- a/test/fixtures/flow/declare-module/3/expected.json +++ b/test/fixtures/flow/declare-module/3/expected.json @@ -137,7 +137,8 @@ } } ] - } + }, + "kind": "CommonJS" } ], "directives": [] diff --git a/test/fixtures/flow/declare-module/4/expected.json b/test/fixtures/flow/declare-module/4/expected.json index a22533aca2..71deaaf280 100644 --- a/test/fixtures/flow/declare-module/4/expected.json +++ b/test/fixtures/flow/declare-module/4/expected.json @@ -156,7 +156,8 @@ "predicate": null } ] - } + }, + "kind": "CommonJS" } ], "directives": [] diff --git a/test/fixtures/flow/declare-module/5/expected.json b/test/fixtures/flow/declare-module/5/expected.json index 27fad53409..d6491c6f37 100644 --- a/test/fixtures/flow/declare-module/5/expected.json +++ b/test/fixtures/flow/declare-module/5/expected.json @@ -138,6 +138,25 @@ "column": 50 } }, + "key": { + "type": "Identifier", + "start": 37, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 40 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 37, @@ -171,24 +190,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 37, - "end": 40, - "loc": { - "start": { - "line": 1, - "column": 37 - }, - "end": { - "line": 1, - "column": 40 - }, - "identifierName": "foo" - }, - "name": "foo" - }, "optional": false } ], @@ -197,7 +198,8 @@ } } ] - } + }, + "kind": "CommonJS" } ], "directives": [] diff --git a/test/fixtures/flow/declare-module/6/expected.json b/test/fixtures/flow/declare-module/6/expected.json index 8024e7d3d1..7b1772c283 100644 --- a/test/fixtures/flow/declare-module/6/expected.json +++ b/test/fixtures/flow/declare-module/6/expected.json @@ -132,6 +132,25 @@ "column": 58 } }, + "key": { + "type": "Identifier", + "start": 45, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 48 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 45, @@ -165,24 +184,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 45, - "end": 48, - "loc": { - "start": { - "line": 1, - "column": 45 - }, - "end": { - "line": 1, - "column": 48 - }, - "identifierName": "foo" - }, - "name": "foo" - }, "optional": false } ], @@ -192,7 +193,8 @@ } } ] - } + }, + "kind": "CommonJS" } ], "directives": [] diff --git a/test/fixtures/flow/declare-module/9/expected.json b/test/fixtures/flow/declare-module/9/expected.json index d549499d21..37a6fe2711 100644 --- a/test/fixtures/flow/declare-module/9/expected.json +++ b/test/fixtures/flow/declare-module/9/expected.json @@ -120,7 +120,8 @@ } } ] - } + }, + "kind": "CommonJS" } ], "directives": [] diff --git a/test/fixtures/flow/declare-module/import/expected.json b/test/fixtures/flow/declare-module/import/expected.json index 391e0de595..f1f57afa41 100644 --- a/test/fixtures/flow/declare-module/import/expected.json +++ b/test/fixtures/flow/declare-module/import/expected.json @@ -148,7 +148,8 @@ } } ] - } + }, + "kind": "CommonJS" } ], "directives": [] diff --git a/test/fixtures/flow/declare-module/invalid-commonjs-module/actual.js b/test/fixtures/flow/declare-module/invalid-commonjs-module/actual.js new file mode 100644 index 0000000000..094feacb53 --- /dev/null +++ b/test/fixtures/flow/declare-module/invalid-commonjs-module/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare module.exports: number; declare export var a: number; } diff --git a/test/fixtures/flow/declare-module/invalid-commonjs-module/options.json b/test/fixtures/flow/declare-module/invalid-commonjs-module/options.json new file mode 100644 index 0000000000..adfde32363 --- /dev/null +++ b/test/fixtures/flow/declare-module/invalid-commonjs-module/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module (1:55)" +} diff --git a/test/fixtures/flow/declare-module/invalid-es-module/actual.js b/test/fixtures/flow/declare-module/invalid-es-module/actual.js new file mode 100644 index 0000000000..111a0c6927 --- /dev/null +++ b/test/fixtures/flow/declare-module/invalid-es-module/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare export var a: number; declare module.exports: number; } diff --git a/test/fixtures/flow/declare-module/invalid-es-module/options.json b/test/fixtures/flow/declare-module/invalid-es-module/options.json new file mode 100644 index 0000000000..b40239a560 --- /dev/null +++ b/test/fixtures/flow/declare-module/invalid-es-module/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module (1:53)" +} diff --git a/test/fixtures/flow/declare-module/invalid-module-in-module/actual.js b/test/fixtures/flow/declare-module/invalid-module-in-module/actual.js new file mode 100644 index 0000000000..7b0be343c3 --- /dev/null +++ b/test/fixtures/flow/declare-module/invalid-module-in-module/actual.js @@ -0,0 +1 @@ +declare module A { declare module B {} } diff --git a/test/fixtures/flow/declare-module/invalid-module-in-module/options.json b/test/fixtures/flow/declare-module/invalid-module-in-module/options.json new file mode 100644 index 0000000000..cd823bd7c4 --- /dev/null +++ b/test/fixtures/flow/declare-module/invalid-module-in-module/options.json @@ -0,0 +1,3 @@ +{ + "throws": "`declare module` cannot be used inside another `declare module` (1:27)" +} diff --git a/test/fixtures/flow/declare-module/invalid-multiple-commonjs/actual.js b/test/fixtures/flow/declare-module/invalid-multiple-commonjs/actual.js new file mode 100644 index 0000000000..3c6d3a0307 --- /dev/null +++ b/test/fixtures/flow/declare-module/invalid-multiple-commonjs/actual.js @@ -0,0 +1 @@ +declare module "foo" { declare module.exports: string; declare module.exports: number; } diff --git a/test/fixtures/flow/declare-module/invalid-multiple-commonjs/options.json b/test/fixtures/flow/declare-module/invalid-multiple-commonjs/options.json new file mode 100644 index 0000000000..1520d766b0 --- /dev/null +++ b/test/fixtures/flow/declare-module/invalid-multiple-commonjs/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Duplicate `declare module.exports` statement (1:55)" +} diff --git a/test/fixtures/flow/declare-statements/10/expected.json b/test/fixtures/flow/declare-statements/10/expected.json index 2e0049fb41..378c963659 100644 --- a/test/fixtures/flow/declare-statements/10/expected.json +++ b/test/fixtures/flow/declare-statements/10/expected.json @@ -92,6 +92,25 @@ "column": 38 } }, + "key": { + "type": "Identifier", + "start": 25, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "static": true, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 18, @@ -125,24 +144,6 @@ } } }, - "static": true, - "key": { - "type": "Identifier", - "start": 25, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 28 - }, - "identifierName": "foo" - }, - "name": "foo" - }, "optional": false }, { @@ -176,6 +177,8 @@ }, "name": "x" }, + "static": true, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 51, @@ -191,9 +194,8 @@ } } }, - "optional": false, - "static": true, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/declare-statements/15/expected.json b/test/fixtures/flow/declare-statements/15/expected.json index 0b5376ca37..6b3d9f0b04 100644 --- a/test/fixtures/flow/declare-statements/15/expected.json +++ b/test/fixtures/flow/declare-statements/15/expected.json @@ -109,6 +109,8 @@ }, "name": "foo" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 27, @@ -124,9 +126,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -247,6 +248,8 @@ }, "name": "foo" }, + "static": false, + "kind": "init", "value": { "type": "GenericTypeAnnotation", "start": 66, @@ -280,9 +283,8 @@ "name": "T" } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/declare-statements/17/expected.json b/test/fixtures/flow/declare-statements/17/expected.json index 381229ee19..2f4a6dc1cb 100644 --- a/test/fixtures/flow/declare-statements/17/expected.json +++ b/test/fixtures/flow/declare-statements/17/expected.json @@ -109,6 +109,8 @@ }, "name": "a" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 22, @@ -124,9 +126,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -159,6 +160,8 @@ }, "name": "b" }, + "static": true, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 41, @@ -174,9 +177,8 @@ } } }, - "optional": false, - "static": true, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -209,6 +211,8 @@ }, "name": "c" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 53, @@ -224,9 +228,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/declare-statements/7/expected.json b/test/fixtures/flow/declare-statements/7/expected.json index 776a6a6a9e..babd12a4f5 100644 --- a/test/fixtures/flow/declare-statements/7/expected.json +++ b/test/fixtures/flow/declare-statements/7/expected.json @@ -92,6 +92,25 @@ "column": 71 } }, + "key": { + "type": "Identifier", + "start": 29, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 39 + }, + "identifierName": "didAnimate" + }, + "name": "didAnimate" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 29, @@ -240,24 +259,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 29, - "end": 39, - "loc": { - "start": { - "line": 1, - "column": 29 - }, - "end": { - "line": 1, - "column": 39 - }, - "identifierName": "didAnimate" - }, - "name": "didAnimate" - }, "optional": false } ], diff --git a/test/fixtures/flow/declare-statements/9/expected.json b/test/fixtures/flow/declare-statements/9/expected.json index 1ac09b01e8..3bafe9b3ab 100644 --- a/test/fixtures/flow/declare-statements/9/expected.json +++ b/test/fixtures/flow/declare-statements/9/expected.json @@ -225,6 +225,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 37, @@ -240,9 +242,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/declare-statements/invalid-literal/actual.js b/test/fixtures/flow/declare-statements/invalid-literal/actual.js new file mode 100644 index 0000000000..b70552565f --- /dev/null +++ b/test/fixtures/flow/declare-statements/invalid-literal/actual.js @@ -0,0 +1 @@ +declare 1; diff --git a/test/fixtures/flow/declare-statements/invalid-literal/options.json b/test/fixtures/flow/declare-statements/invalid-literal/options.json new file mode 100644 index 0000000000..1288082ab0 --- /dev/null +++ b/test/fixtures/flow/declare-statements/invalid-literal/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ; (1:8)" +} diff --git a/test/fixtures/flow/interfaces-module-and-script/10/expected.json b/test/fixtures/flow/interfaces-module-and-script/10/expected.json index 4c7e6d03c9..4fb5918fb1 100644 --- a/test/fixtures/flow/interfaces-module-and-script/10/expected.json +++ b/test/fixtures/flow/interfaces-module-and-script/10/expected.json @@ -159,6 +159,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "BooleanTypeAnnotation", "start": 22, @@ -174,9 +176,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -209,6 +210,8 @@ }, "name": "y" }, + "static": true, + "kind": "init", "value": { "type": "BooleanTypeAnnotation", "start": 62, @@ -224,9 +227,8 @@ } } }, - "optional": false, - "static": true, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/interfaces-module-and-script/4/expected.json b/test/fixtures/flow/interfaces-module-and-script/4/expected.json index 1099bd54e8..83636e0555 100644 --- a/test/fixtures/flow/interfaces-module-and-script/4/expected.json +++ b/test/fixtures/flow/interfaces-module-and-script/4/expected.json @@ -109,6 +109,8 @@ }, "name": "foo" }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 19, @@ -142,9 +144,8 @@ }, "typeParameters": null }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/interfaces-module-and-script/5/expected.json b/test/fixtures/flow/interfaces-module-and-script/5/expected.json index 042154f2d0..da45e73fc6 100644 --- a/test/fixtures/flow/interfaces-module-and-script/5/expected.json +++ b/test/fixtures/flow/interfaces-module-and-script/5/expected.json @@ -109,6 +109,8 @@ }, "name": "length" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 56, @@ -124,9 +126,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [ diff --git a/test/fixtures/flow/object-types/invalid-getter-param-count/actual.js b/test/fixtures/flow/object-types/invalid-getter-param-count/actual.js new file mode 100644 index 0000000000..83d9b887fc --- /dev/null +++ b/test/fixtures/flow/object-types/invalid-getter-param-count/actual.js @@ -0,0 +1,3 @@ +type B = { + get a(foo:number): number; +} diff --git a/test/fixtures/flow/object-types/invalid-getter-param-count/options.json b/test/fixtures/flow/object-types/invalid-getter-param-count/options.json new file mode 100644 index 0000000000..8694117aee --- /dev/null +++ b/test/fixtures/flow/object-types/invalid-getter-param-count/options.json @@ -0,0 +1,3 @@ +{ + "throws": "getter should have no params (2:2)" +} diff --git a/test/fixtures/flow/object-types/invalid-setter-param-count/actual.js b/test/fixtures/flow/object-types/invalid-setter-param-count/actual.js new file mode 100644 index 0000000000..1ccbc71755 --- /dev/null +++ b/test/fixtures/flow/object-types/invalid-setter-param-count/actual.js @@ -0,0 +1,3 @@ +type B = { + set a(): void; +} diff --git a/test/fixtures/flow/object-types/invalid-setter-param-count/options.json b/test/fixtures/flow/object-types/invalid-setter-param-count/options.json new file mode 100644 index 0000000000..8ea95ab888 --- /dev/null +++ b/test/fixtures/flow/object-types/invalid-setter-param-count/options.json @@ -0,0 +1,3 @@ +{ + "throws": "setter should have exactly one param (2:2)" +} diff --git a/test/fixtures/flow/type-alias/4/expected.json b/test/fixtures/flow/type-alias/4/expected.json index 42a84bca7b..c45c0020b6 100644 --- a/test/fixtures/flow/type-alias/4/expected.json +++ b/test/fixtures/flow/type-alias/4/expected.json @@ -122,6 +122,8 @@ }, "name": "type" }, + "static": false, + "kind": "init", "value": { "type": "StringLiteralTypeAnnotation", "start": 23, @@ -142,9 +144,8 @@ }, "value": "A" }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -197,6 +198,8 @@ }, "name": "type" }, + "static": false, + "kind": "init", "value": { "type": "StringLiteralTypeAnnotation", "start": 38, @@ -217,9 +220,8 @@ }, "value": "B" }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -521,6 +523,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "UnionTypeAnnotation", "start": 147, @@ -583,6 +587,8 @@ }, "name": "type" }, + "static": false, + "kind": "init", "value": { "type": "StringLiteralTypeAnnotation", "start": 156, @@ -603,9 +609,8 @@ }, "value": "A" }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -658,6 +663,8 @@ }, "name": "type" }, + "static": false, + "kind": "init", "value": { "type": "StringLiteralTypeAnnotation", "start": 174, @@ -678,9 +685,8 @@ }, "value": "B" }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -688,9 +694,8 @@ } ] }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -776,6 +781,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "IntersectionTypeAnnotation", "start": 212, @@ -838,6 +845,8 @@ }, "name": "type" }, + "static": false, + "kind": "init", "value": { "type": "StringLiteralTypeAnnotation", "start": 221, @@ -858,9 +867,8 @@ }, "value": "A" }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -913,6 +921,8 @@ }, "name": "type" }, + "static": false, + "kind": "init", "value": { "type": "StringLiteralTypeAnnotation", "start": 239, @@ -933,9 +943,8 @@ }, "value": "B" }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -943,9 +952,8 @@ } ] }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/108/expected.json b/test/fixtures/flow/type-annotations/108/expected.json index cc7cae44e2..54aad24d12 100644 --- a/test/fixtures/flow/type-annotations/108/expected.json +++ b/test/fixtures/flow/type-annotations/108/expected.json @@ -134,6 +134,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 14, @@ -149,9 +151,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -184,6 +185,8 @@ }, "name": "y" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 25, @@ -199,9 +202,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -446,6 +448,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 71, @@ -461,9 +465,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -496,6 +499,8 @@ }, "name": "y" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 82, @@ -511,9 +516,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -858,6 +862,8 @@ }, "name": "a" }, + "static": false, + "kind": "init", "value": { "type": "ObjectTypeAnnotation", "start": 148, @@ -905,6 +911,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 154, @@ -920,9 +928,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -955,6 +962,8 @@ }, "name": "y" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 165, @@ -970,17 +979,15 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], "exact": true }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -1013,6 +1020,8 @@ }, "name": "b" }, + "static": false, + "kind": "init", "value": { "type": "BooleanTypeAnnotation", "start": 179, @@ -1028,9 +1037,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -1378,6 +1386,8 @@ }, "name": "a" }, + "static": false, + "kind": "init", "value": { "type": "ObjectTypeAnnotation", "start": 242, @@ -1425,6 +1435,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 247, @@ -1440,9 +1452,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -1475,6 +1486,8 @@ }, "name": "y" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 258, @@ -1490,17 +1503,15 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], "exact": false }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -1533,6 +1544,8 @@ }, "name": "b" }, + "static": false, + "kind": "init", "value": { "type": "BooleanTypeAnnotation", "start": 271, @@ -1548,9 +1561,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/110/expected.json b/test/fixtures/flow/type-annotations/110/expected.json index f637eb85b6..063bbf7e97 100644 --- a/test/fixtures/flow/type-annotations/110/expected.json +++ b/test/fixtures/flow/type-annotations/110/expected.json @@ -107,6 +107,8 @@ }, "name": "p" }, + "static": false, + "kind": "init", "value": { "type": "GenericTypeAnnotation", "start": 13, @@ -140,8 +142,6 @@ "name": "T" } }, - "optional": false, - "static": false, "variance": { "type": "Variance", "start": 10, @@ -157,7 +157,8 @@ } }, "kind": "plus" - } + }, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/111/expected.json b/test/fixtures/flow/type-annotations/111/expected.json index 088ac9c758..02766a4758 100644 --- a/test/fixtures/flow/type-annotations/111/expected.json +++ b/test/fixtures/flow/type-annotations/111/expected.json @@ -107,6 +107,8 @@ }, "name": "p" }, + "static": false, + "kind": "init", "value": { "type": "GenericTypeAnnotation", "start": 13, @@ -140,8 +142,6 @@ "name": "T" } }, - "optional": false, - "static": false, "variance": { "type": "Variance", "start": 10, @@ -157,7 +157,8 @@ } }, "kind": "minus" - } + }, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/136/expected.json b/test/fixtures/flow/type-annotations/136/expected.json index ca0bd530db..6ccd7002c9 100644 --- a/test/fixtures/flow/type-annotations/136/expected.json +++ b/test/fixtures/flow/type-annotations/136/expected.json @@ -107,6 +107,8 @@ }, "name": "p" }, + "static": false, + "kind": "init", "value": { "type": "ObjectTypeAnnotation", "start": 15, @@ -126,9 +128,8 @@ "indexers": [], "exact": false }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeSpreadProperty", diff --git a/test/fixtures/flow/type-annotations/32/expected.json b/test/fixtures/flow/type-annotations/32/expected.json index ce82a0dbf1..2009fe86e1 100644 --- a/test/fixtures/flow/type-annotations/32/expected.json +++ b/test/fixtures/flow/type-annotations/32/expected.json @@ -134,6 +134,8 @@ }, "name": "numVal" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 16, @@ -149,9 +151,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/33/expected.json b/test/fixtures/flow/type-annotations/33/expected.json index 7739fea5f1..20c064ef1a 100644 --- a/test/fixtures/flow/type-annotations/33/expected.json +++ b/test/fixtures/flow/type-annotations/33/expected.json @@ -134,6 +134,8 @@ }, "name": "numVal" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 16, @@ -149,9 +151,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/34/expected.json b/test/fixtures/flow/type-annotations/34/expected.json index aa0ad93518..8214472aee 100644 --- a/test/fixtures/flow/type-annotations/34/expected.json +++ b/test/fixtures/flow/type-annotations/34/expected.json @@ -134,6 +134,8 @@ }, "name": "numVal" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 16, @@ -149,9 +151,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [ diff --git a/test/fixtures/flow/type-annotations/35/expected.json b/test/fixtures/flow/type-annotations/35/expected.json index 226236359b..0a016d2518 100644 --- a/test/fixtures/flow/type-annotations/35/expected.json +++ b/test/fixtures/flow/type-annotations/35/expected.json @@ -148,6 +148,8 @@ }, "name": "numVal" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 17, @@ -163,9 +165,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/36/expected.json b/test/fixtures/flow/type-annotations/36/expected.json index 4ccc7c692f..31e1d58d02 100644 --- a/test/fixtures/flow/type-annotations/36/expected.json +++ b/test/fixtures/flow/type-annotations/36/expected.json @@ -134,6 +134,8 @@ }, "name": "numVal" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 16, @@ -149,9 +151,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -184,6 +185,8 @@ }, "name": "strVal" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 32, @@ -199,9 +202,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/37/expected.json b/test/fixtures/flow/type-annotations/37/expected.json index ef13a1423d..5c4dbc804f 100644 --- a/test/fixtures/flow/type-annotations/37/expected.json +++ b/test/fixtures/flow/type-annotations/37/expected.json @@ -134,6 +134,8 @@ }, "name": "subObj" }, + "static": false, + "kind": "init", "value": { "type": "ObjectTypeAnnotation", "start": 16, @@ -181,6 +183,8 @@ }, "name": "strVal" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 25, @@ -196,17 +200,15 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], "exact": false }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/38/expected.json b/test/fixtures/flow/type-annotations/38/expected.json index a37a224c5e..13365bd73e 100644 --- a/test/fixtures/flow/type-annotations/38/expected.json +++ b/test/fixtures/flow/type-annotations/38/expected.json @@ -134,6 +134,8 @@ }, "name": "subObj" }, + "static": false, + "kind": "init", "value": { "type": "NullableTypeAnnotation", "start": 16, @@ -195,6 +197,8 @@ }, "name": "strVal" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 26, @@ -210,18 +214,16 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], "exact": false } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/39/expected.json b/test/fixtures/flow/type-annotations/39/expected.json index ba0346f3e3..ff7898371e 100644 --- a/test/fixtures/flow/type-annotations/39/expected.json +++ b/test/fixtures/flow/type-annotations/39/expected.json @@ -134,6 +134,8 @@ }, "name": "param1" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 16, @@ -149,9 +151,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -184,6 +185,8 @@ }, "name": "param2" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 32, @@ -199,9 +202,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/40/expected.json b/test/fixtures/flow/type-annotations/40/expected.json index bd5b46e71f..fc457a1df3 100644 --- a/test/fixtures/flow/type-annotations/40/expected.json +++ b/test/fixtures/flow/type-annotations/40/expected.json @@ -134,6 +134,8 @@ }, "name": "param1" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 16, @@ -149,9 +151,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -184,6 +185,8 @@ }, "name": "param2" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 33, @@ -199,9 +202,8 @@ } } }, - "optional": true, - "static": false, - "variance": null + "variance": null, + "optional": true } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/42/expected.json b/test/fixtures/flow/type-annotations/42/expected.json index c02588c4e6..71e3447c35 100644 --- a/test/fixtures/flow/type-annotations/42/expected.json +++ b/test/fixtures/flow/type-annotations/42/expected.json @@ -117,6 +117,25 @@ "column": 47 } }, + "key": { + "type": "Identifier", + "start": 8, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "add" + }, + "name": "add" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 8, @@ -295,24 +314,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 8, - "end": 11, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 1, - "column": 11 - }, - "identifierName": "add" - }, - "name": "add" - }, "optional": false } ], diff --git a/test/fixtures/flow/type-annotations/43/expected.json b/test/fixtures/flow/type-annotations/43/expected.json index d888673773..07ba5008e4 100644 --- a/test/fixtures/flow/type-annotations/43/expected.json +++ b/test/fixtures/flow/type-annotations/43/expected.json @@ -117,6 +117,25 @@ "column": 23 } }, + "key": { + "type": "Identifier", + "start": 9, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "id" + }, + "name": "id" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 9, @@ -268,24 +287,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 9, - "end": 11, - "loc": { - "start": { - "line": 1, - "column": 9 - }, - "end": { - "line": 1, - "column": 11 - }, - "identifierName": "id" - }, - "name": "id" - }, "optional": false } ], diff --git a/test/fixtures/flow/type-annotations/60/expected.json b/test/fixtures/flow/type-annotations/60/expected.json index 71d0a6e5f9..7bcec9cc23 100644 --- a/test/fixtures/flow/type-annotations/60/expected.json +++ b/test/fixtures/flow/type-annotations/60/expected.json @@ -189,6 +189,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 13, @@ -204,9 +206,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/61/expected.json b/test/fixtures/flow/type-annotations/61/expected.json index b08974f765..d67405b5b2 100644 --- a/test/fixtures/flow/type-annotations/61/expected.json +++ b/test/fixtures/flow/type-annotations/61/expected.json @@ -189,6 +189,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 13, @@ -204,9 +206,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/63/expected.json b/test/fixtures/flow/type-annotations/63/expected.json index e0bbfe124f..9317604671 100644 --- a/test/fixtures/flow/type-annotations/63/expected.json +++ b/test/fixtures/flow/type-annotations/63/expected.json @@ -195,6 +195,8 @@ }, "name": "x" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 23, @@ -210,9 +212,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-annotations/98/expected.json b/test/fixtures/flow/type-annotations/98/expected.json index 7100fa77f8..0b51971251 100644 --- a/test/fixtures/flow/type-annotations/98/expected.json +++ b/test/fixtures/flow/type-annotations/98/expected.json @@ -134,6 +134,8 @@ }, "name": "param1" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 17, @@ -149,9 +151,8 @@ } } }, - "optional": true, - "static": false, - "variance": null + "variance": null, + "optional": true }, { "type": "ObjectTypeProperty", @@ -184,6 +185,8 @@ }, "name": "param2" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 33, @@ -199,9 +202,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -234,6 +236,8 @@ }, "name": "param3" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 49, @@ -249,9 +253,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-exports/interface/expected.json b/test/fixtures/flow/type-exports/interface/expected.json index 45366de3c4..f835d903ed 100644 --- a/test/fixtures/flow/type-exports/interface/expected.json +++ b/test/fixtures/flow/type-exports/interface/expected.json @@ -126,6 +126,8 @@ }, "name": "p" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 26, @@ -141,9 +143,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], @@ -297,6 +298,8 @@ }, "name": "p" }, + "static": false, + "kind": "init", "value": { "type": "GenericTypeAnnotation", "start": 65, @@ -330,9 +333,8 @@ "name": "T" } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [], diff --git a/test/fixtures/flow/type-parameter-declaration/declare-class-method-reserved-word/expected.json b/test/fixtures/flow/type-parameter-declaration/declare-class-method-reserved-word/expected.json index df4896c159..c70f16d94e 100644 --- a/test/fixtures/flow/type-parameter-declaration/declare-class-method-reserved-word/expected.json +++ b/test/fixtures/flow/type-parameter-declaration/declare-class-method-reserved-word/expected.json @@ -92,6 +92,25 @@ "column": 19 } }, + "key": { + "type": "Identifier", + "start": 20, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "foobar" + }, + "name": "foobar" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 20, @@ -158,24 +177,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 20, - "end": 26, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 8 - }, - "identifierName": "foobar" - }, - "name": "foobar" - }, "optional": false }, { @@ -192,6 +193,25 @@ "column": 19 } }, + "key": { + "type": "Identifier", + "start": 41, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "delete" + }, + "name": "delete" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 41, @@ -258,24 +278,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 41, - "end": 47, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 8 - }, - "identifierName": "delete" - }, - "name": "delete" - }, "optional": false }, { @@ -292,6 +294,25 @@ "column": 18 } }, + "key": { + "type": "Identifier", + "start": 62, + "end": 67, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 62, @@ -358,24 +379,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 62, - "end": 67, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 7 - }, - "identifierName": "yield" - }, - "name": "yield" - }, "optional": false }, { @@ -392,6 +395,25 @@ "column": 15 } }, + "key": { + "type": "Identifier", + "start": 82, + "end": 84, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 4 + }, + "identifierName": "do" + }, + "name": "do" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 82, @@ -458,24 +480,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 82, - "end": 84, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 4 - }, - "identifierName": "do" - }, - "name": "do" - }, "optional": false }, { @@ -492,6 +496,25 @@ "column": 26 } }, + "key": { + "type": "Identifier", + "start": 106, + "end": 112, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 15 + }, + "identifierName": "foobar" + }, + "name": "foobar" + }, + "static": true, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 99, @@ -558,24 +581,6 @@ } } }, - "static": true, - "key": { - "type": "Identifier", - "start": 106, - "end": 112, - "loc": { - "start": { - "line": 6, - "column": 9 - }, - "end": { - "line": 6, - "column": 15 - }, - "identifierName": "foobar" - }, - "name": "foobar" - }, "optional": false }, { @@ -592,6 +597,25 @@ "column": 26 } }, + "key": { + "type": "Identifier", + "start": 134, + "end": 140, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 15 + }, + "identifierName": "delete" + }, + "name": "delete" + }, + "static": true, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 127, @@ -658,24 +682,6 @@ } } }, - "static": true, - "key": { - "type": "Identifier", - "start": 134, - "end": 140, - "loc": { - "start": { - "line": 7, - "column": 9 - }, - "end": { - "line": 7, - "column": 15 - }, - "identifierName": "delete" - }, - "name": "delete" - }, "optional": false }, { @@ -692,6 +698,25 @@ "column": 25 } }, + "key": { + "type": "Identifier", + "start": 162, + "end": 167, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "static": true, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 155, @@ -758,24 +783,6 @@ } } }, - "static": true, - "key": { - "type": "Identifier", - "start": 162, - "end": 167, - "loc": { - "start": { - "line": 8, - "column": 9 - }, - "end": { - "line": 8, - "column": 14 - }, - "identifierName": "yield" - }, - "name": "yield" - }, "optional": false }, { @@ -792,6 +799,25 @@ "column": 22 } }, + "key": { + "type": "Identifier", + "start": 189, + "end": 191, + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 11 + }, + "identifierName": "do" + }, + "name": "do" + }, + "static": true, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 182, @@ -858,24 +884,6 @@ } } }, - "static": true, - "key": { - "type": "Identifier", - "start": 189, - "end": 191, - "loc": { - "start": { - "line": 9, - "column": 9 - }, - "end": { - "line": 9, - "column": 11 - }, - "identifierName": "do" - }, - "name": "do" - }, "optional": false } ], diff --git a/test/fixtures/flow/type-parameter-declaration/declare-interface-method-reserved-word/expected.json b/test/fixtures/flow/type-parameter-declaration/declare-interface-method-reserved-word/expected.json index d6ee0660f0..1bc3f578c1 100644 --- a/test/fixtures/flow/type-parameter-declaration/declare-interface-method-reserved-word/expected.json +++ b/test/fixtures/flow/type-parameter-declaration/declare-interface-method-reserved-word/expected.json @@ -92,6 +92,25 @@ "column": 19 } }, + "key": { + "type": "Identifier", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "foobar" + }, + "name": "foobar" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 24, @@ -158,24 +177,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 24, - "end": 30, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 8 - }, - "identifierName": "foobar" - }, - "name": "foobar" - }, "optional": false }, { @@ -192,6 +193,25 @@ "column": 19 } }, + "key": { + "type": "Identifier", + "start": 45, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "delete" + }, + "name": "delete" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 45, @@ -258,24 +278,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 45, - "end": 51, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 8 - }, - "identifierName": "delete" - }, - "name": "delete" - }, "optional": false }, { @@ -292,6 +294,25 @@ "column": 18 } }, + "key": { + "type": "Identifier", + "start": 66, + "end": 71, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 66, @@ -358,24 +379,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 66, - "end": 71, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 7 - }, - "identifierName": "yield" - }, - "name": "yield" - }, "optional": false }, { @@ -392,6 +395,25 @@ "column": 15 } }, + "key": { + "type": "Identifier", + "start": 86, + "end": 88, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 4 + }, + "identifierName": "do" + }, + "name": "do" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 86, @@ -458,24 +480,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 86, - "end": 88, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 4 - }, - "identifierName": "do" - }, - "name": "do" - }, "optional": false } ], diff --git a/test/fixtures/flow/type-parameter-declaration/interface-reserved-word/expected.json b/test/fixtures/flow/type-parameter-declaration/interface-reserved-word/expected.json index d14c0aa7a3..42e5d3ce8b 100644 --- a/test/fixtures/flow/type-parameter-declaration/interface-reserved-word/expected.json +++ b/test/fixtures/flow/type-parameter-declaration/interface-reserved-word/expected.json @@ -92,6 +92,25 @@ "column": 19 } }, + "key": { + "type": "Identifier", + "start": 16, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "foobar" + }, + "name": "foobar" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 16, @@ -158,24 +177,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 16, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 8 - }, - "identifierName": "foobar" - }, - "name": "foobar" - }, "optional": false }, { @@ -192,6 +193,25 @@ "column": 19 } }, + "key": { + "type": "Identifier", + "start": 37, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "delete" + }, + "name": "delete" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 37, @@ -258,24 +278,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 37, - "end": 43, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 8 - }, - "identifierName": "delete" - }, - "name": "delete" - }, "optional": false }, { @@ -292,6 +294,25 @@ "column": 18 } }, + "key": { + "type": "Identifier", + "start": 58, + "end": 63, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 58, @@ -358,24 +379,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 58, - "end": 63, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 7 - }, - "identifierName": "yield" - }, - "name": "yield" - }, "optional": false }, { @@ -392,6 +395,25 @@ "column": 15 } }, + "key": { + "type": "Identifier", + "start": 78, + "end": 80, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 4 + }, + "identifierName": "do" + }, + "name": "do" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 78, @@ -458,24 +480,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 78, - "end": 80, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 4 - }, - "identifierName": "do" - }, - "name": "do" - }, "optional": false } ], diff --git a/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/expected.json b/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/expected.json index c3bb865167..5847ba7708 100644 --- a/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/expected.json +++ b/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/expected.json @@ -90,6 +90,25 @@ "column": 19 } }, + "key": { + "type": "Identifier", + "start": 13, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "foobar" + }, + "name": "foobar" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 13, @@ -156,24 +175,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 13, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 8 - }, - "identifierName": "foobar" - }, - "name": "foobar" - }, "optional": false }, { @@ -190,6 +191,25 @@ "column": 19 } }, + "key": { + "type": "Identifier", + "start": 34, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "delete" + }, + "name": "delete" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 34, @@ -256,24 +276,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 34, - "end": 40, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 8 - }, - "identifierName": "delete" - }, - "name": "delete" - }, "optional": false }, { @@ -290,6 +292,25 @@ "column": 18 } }, + "key": { + "type": "Identifier", + "start": 55, + "end": 60, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 55, @@ -356,24 +377,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 55, - "end": 60, - "loc": { - "start": { - "line": 4, - "column": 2 - }, - "end": { - "line": 4, - "column": 7 - }, - "identifierName": "yield" - }, - "name": "yield" - }, "optional": false }, { @@ -390,6 +393,25 @@ "column": 15 } }, + "key": { + "type": "Identifier", + "start": 75, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 4 + }, + "identifierName": "do" + }, + "name": "do" + }, + "static": false, + "kind": "init", "value": { "type": "FunctionTypeAnnotation", "start": 75, @@ -456,24 +478,6 @@ } } }, - "static": false, - "key": { - "type": "Identifier", - "start": 75, - "end": 77, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 4 - }, - "identifierName": "do" - }, - "name": "do" - }, "optional": false } ], diff --git a/test/fixtures/flow/typecasts/2/expected.json b/test/fixtures/flow/typecasts/2/expected.json index e9f527ccb8..e41a4f7b34 100644 --- a/test/fixtures/flow/typecasts/2/expected.json +++ b/test/fixtures/flow/typecasts/2/expected.json @@ -244,6 +244,8 @@ }, "name": "xxx" }, + "static": false, + "kind": "init", "value": { "type": "NumberTypeAnnotation", "start": 29, @@ -259,9 +261,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false }, { "type": "ObjectTypeProperty", @@ -294,6 +295,8 @@ }, "name": "yyy" }, + "static": false, + "kind": "init", "value": { "type": "StringTypeAnnotation", "start": 42, @@ -309,9 +312,8 @@ } } }, - "optional": false, - "static": false, - "variance": null + "variance": null, + "optional": false } ], "indexers": [],