|
|
@ -1,4 +1,5 @@
|
|
|
|
import { Parser } from '../index';
|
|
|
|
import { Parser } from '../index';
|
|
|
|
|
|
|
|
import { reserved } from '../../utils/names';
|
|
|
|
|
|
|
|
|
|
|
|
interface Identifier {
|
|
|
|
interface Identifier {
|
|
|
|
start: number;
|
|
|
|
start: number;
|
|
|
@ -116,8 +117,11 @@ export default function read_context(parser: Parser) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: DRY this out somehow
|
|
|
|
|
|
|
|
// We don't know whether we want to allow reserved words until we see whether there's a ':' after it
|
|
|
|
|
|
|
|
// Probably ideally we'd use Acorn to do all of this
|
|
|
|
const start = parser.index;
|
|
|
|
const start = parser.index;
|
|
|
|
const name = parser.read_identifier();
|
|
|
|
const name = parser.read_identifier(true);
|
|
|
|
const key: Identifier = {
|
|
|
|
const key: Identifier = {
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end: parser.index,
|
|
|
|
end: parser.index,
|
|
|
@ -126,9 +130,19 @@ export default function read_context(parser: Parser) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
|
|
|
|
|
|
|
|
const value = parser.eat(':')
|
|
|
|
let value: Context;
|
|
|
|
? (parser.allow_whitespace(), read_context(parser))
|
|
|
|
if (parser.eat(':')) {
|
|
|
|
: key;
|
|
|
|
parser.allow_whitespace();
|
|
|
|
|
|
|
|
value = read_context(parser);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (reserved.has(name)) {
|
|
|
|
|
|
|
|
parser.error({
|
|
|
|
|
|
|
|
code: `unexpected-reserved-word`,
|
|
|
|
|
|
|
|
message: `'${name}' is a reserved word in JavaScript and cannot be used here`
|
|
|
|
|
|
|
|
}, start);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
value = key;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const property: Property = {
|
|
|
|
const property: Property = {
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|