Add support for declare module.exports (#72)
* Add support for declare module.exports * Use doublequotes * Use expect instead of eat
This commit is contained in:
parent
fd18d89d8e
commit
f576865ce9
@ -66,7 +66,11 @@ pp.flowParseDeclare = function (node) {
|
||||
} else if (this.match(tt._var)) {
|
||||
return this.flowParseDeclareVariable(node);
|
||||
} else if (this.isContextual("module")) {
|
||||
return this.flowParseDeclareModule(node);
|
||||
if (this.lookahead().type === tt.dot) {
|
||||
return this.flowParseDeclareModuleExports(node);
|
||||
} else {
|
||||
return this.flowParseDeclareModule(node);
|
||||
}
|
||||
} else if (this.isContextual("type")) {
|
||||
return this.flowParseDeclareTypeAlias(node);
|
||||
} else if (this.isContextual("interface")) {
|
||||
@ -109,6 +113,14 @@ pp.flowParseDeclareModule = function (node) {
|
||||
return this.finishNode(node, "DeclareModule");
|
||||
};
|
||||
|
||||
pp.flowParseDeclareModuleExports = function (node) {
|
||||
this.expectContextual("module");
|
||||
this.expect(tt.dot);
|
||||
this.expectContextual("exports");
|
||||
node.typeAnnotation = this.flowParseTypeAnnotation();
|
||||
return this.finishNode(node, "DeclareModuleExports");
|
||||
};
|
||||
|
||||
pp.flowParseDeclareTypeAlias = function (node) {
|
||||
this.next();
|
||||
this.flowParseTypeAlias(node);
|
||||
|
||||
1
test/fixtures/flow/declare-module/6/actual.js
vendored
Normal file
1
test/fixtures/flow/declare-module/6/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
declare module A { declare module.exports: { foo(): number; } }
|
||||
196
test/fixtures/flow/declare-module/6/expected.json
vendored
Normal file
196
test/fixtures/flow/declare-module/6/expected.json
vendored
Normal file
@ -0,0 +1,196 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 63,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 63
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 63,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 63
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "DeclareModule",
|
||||
"start": 0,
|
||||
"end": 63,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 63
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 15,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
}
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 17,
|
||||
"end": 63,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 17
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 63
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "DeclareModuleExports",
|
||||
"start": 19,
|
||||
"end": 61,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 19
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 61
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TypeAnnotation",
|
||||
"start": 41,
|
||||
"end": 61,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 41
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 61
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "ObjectTypeAnnotation",
|
||||
"start": 43,
|
||||
"end": 61,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 43
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 61
|
||||
}
|
||||
},
|
||||
"callProperties": [],
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectTypeProperty",
|
||||
"start": 45,
|
||||
"end": 59,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 45
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 59
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "FunctionTypeAnnotation",
|
||||
"start": 45,
|
||||
"end": 58,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 45
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 58
|
||||
}
|
||||
},
|
||||
"params": [],
|
||||
"rest": null,
|
||||
"typeParameters": null,
|
||||
"returnType": {
|
||||
"type": "NumberTypeAnnotation",
|
||||
"start": 52,
|
||||
"end": 58,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 52
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 58
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 45,
|
||||
"end": 48,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 45
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 48
|
||||
}
|
||||
},
|
||||
"name": "foo"
|
||||
},
|
||||
"optional": false
|
||||
}
|
||||
],
|
||||
"indexers": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
test/fixtures/flow/declare-module/7/actual.js
vendored
Normal file
1
test/fixtures/flow/declare-module/7/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
declare module A { declare module.foo: { foo(): number; } }
|
||||
3
test/fixtures/flow/declare-module/7/options.json
vendored
Normal file
3
test/fixtures/flow/declare-module/7/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Unexpected token (1:34)"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user