Only allow declares inside declare module (#73)
* Only allow declares inside declare module * Better error message
This commit is contained in:
parent
4811d617ce
commit
eb691425b6
@ -45,8 +45,8 @@ pp.eatContextual = function (name) {
|
||||
|
||||
// Asserts that following token is given contextual keyword.
|
||||
|
||||
pp.expectContextual = function (name) {
|
||||
if (!this.eatContextual(name)) this.unexpected();
|
||||
pp.expectContextual = function (name, message) {
|
||||
if (!this.eatContextual(name)) this.unexpected(null, message);
|
||||
};
|
||||
|
||||
// Test whether a semicolon can be inserted at the current position.
|
||||
@ -79,6 +79,6 @@ pp.expect = function (type) {
|
||||
|
||||
// Raise an unexpected token error.
|
||||
|
||||
pp.unexpected = function (pos) {
|
||||
this.raise(pos != null ? pos : this.state.start, "Unexpected token");
|
||||
pp.unexpected = function (pos, message = "Unexpected token") {
|
||||
this.raise(pos != null ? pos : this.state.start, message);
|
||||
};
|
||||
|
||||
@ -102,8 +102,7 @@ pp.flowParseDeclareModule = function (node) {
|
||||
while (!this.match(tt.braceR)) {
|
||||
let node2 = this.startNode();
|
||||
|
||||
// todo: declare check
|
||||
this.next();
|
||||
this.expectContextual("declare", "Unexpected token. Only declares are allowed inside declare module");
|
||||
|
||||
body.push(this.flowParseDeclare(node2));
|
||||
}
|
||||
|
||||
3
test/fixtures/flow/declare-module/8/actual.js
vendored
Normal file
3
test/fixtures/flow/declare-module/8/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
declare module A {
|
||||
declar var a:number
|
||||
}
|
||||
3
test/fixtures/flow/declare-module/8/options.json
vendored
Normal file
3
test/fixtures/flow/declare-module/8/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Unexpected token. Only declares are allowed inside declare module (2:2)"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user