Only allow declares inside declare module (#73)

* Only allow declares inside declare module

* Better error message
This commit is contained in:
Daniel Tschinder 2016-07-29 20:22:49 +02:00 committed by GitHub
parent 4811d617ce
commit eb691425b6
4 changed files with 11 additions and 6 deletions

View File

@ -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);
};

View File

@ -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));
}

View File

@ -0,0 +1,3 @@
declare module A {
declar var a:number
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token. Only declares are allowed inside declare module (2:2)"
}