Skip to content

Commit b1a8984

Browse files
Parse provided tag (#203)
1 parent aa472f9 commit b1a8984

File tree

6 files changed

+649
-13
lines changed

6 files changed

+649
-13
lines changed

src/parse.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ export function parseCell(input, {tag, raw, globals, ...options} = {}) {
1818
// is consistent for all empty input cases.
1919
if (tag != null && input) {
2020
cell = TemplateCellParser.parse(input, options);
21-
cell.tag = tag;
21+
const parsedTag = CellTagParser.parse(tag, options);
22+
parseReferences(parsedTag, tag, globals);
23+
parseFeatures(parsedTag, tag);
24+
cell.tag = parsedTag;
2225
cell.raw = !!raw;
2326
} else {
2427
cell = CellParser.parse(input, options);
2528
}
2629
parseReferences(cell, input, globals);
27-
parseFeatures(cell);
30+
parseFeatures(cell, input);
2831
return cell;
2932
}
3033

@@ -386,6 +389,45 @@ export class ModuleParser extends CellParser {
386389
}
387390
}
388391

392+
export class CellTagParser extends Parser {
393+
constructor(options, ...args) {
394+
super(Object.assign({ecmaVersion: 12}, options), ...args);
395+
}
396+
enterScope(flags) {
397+
if (flags & SCOPE_FUNCTION) ++this.O_function;
398+
return super.enterScope(flags);
399+
}
400+
exitScope() {
401+
if (this.currentScope().flags & SCOPE_FUNCTION) --this.O_function;
402+
return super.exitScope();
403+
}
404+
parseForIn(node, init) {
405+
if (this.O_function === 1 && node.await) this.O_async = true;
406+
return super.parseForIn(node, init);
407+
}
408+
parseAwait() {
409+
if (this.O_function === 1) this.O_async = true;
410+
return super.parseAwait();
411+
}
412+
parseYield(noIn) {
413+
if (this.O_function === 1) this.O_generator = true;
414+
return super.parseYield(noIn);
415+
}
416+
parseTopLevel(node) {
417+
this.O_function = 0;
418+
this.O_async = false;
419+
this.O_generator = false;
420+
this.strict = true;
421+
this.enterScope(SCOPE_FUNCTION | SCOPE_ASYNC | SCOPE_GENERATOR);
422+
node.body = this.parseExpression();
423+
node.input = this.input;
424+
node.async = this.O_async;
425+
node.generator = this.O_generator;
426+
this.exitScope();
427+
return this.finishNode(node, "CellTag");
428+
}
429+
}
430+
389431
// Find references.
390432
// Check for illegal references to arguments.
391433
// Check for illegal assignments to global references.

0 commit comments

Comments
 (0)