Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/compiler/src/expression_parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,14 +1059,14 @@ class _ParseAST {
return new PrefixNot(this.span(start), this.sourceSpan(start), result);
}
} else if (this.next.isKeywordTypeof()) {
this.advance();
const start = this.inputIndex;
let result = this.parsePrefix();
this.advance();
const result = this.parsePrefix();
return new TypeofExpression(this.span(start), this.sourceSpan(start), result);
} else if (this.next.isKeywordVoid()) {
this.advance();
const start = this.inputIndex;
let result = this.parsePrefix();
this.advance();
const result = this.parsePrefix();
return new VoidExpression(this.span(start), this.sourceSpan(start), result);
}
return this.parseCallChain();
Expand Down
30 changes: 30 additions & 0 deletions packages/compiler/test/expression_parser/parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,36 @@ describe('parser', () => {
}
});

it('should produce correct span for typeof expression', () => {
const ast = parseAction('foo = typeof bar');

expect(unparseWithSpan(ast)).toEqual([
['foo = typeof bar', 'foo = typeof bar'],
['foo', 'foo'],
['foo', '[nameSpan] foo'],
['', ''],
['typeof bar', 'typeof bar'],
['bar', 'bar'],
['bar', '[nameSpan] bar'],
['', ' '],
]);
});

it('should produce correct span for void expression', () => {
const ast = parseAction('foo = void bar');

expect(unparseWithSpan(ast)).toEqual([
['foo = void bar', 'foo = void bar'],
['foo', 'foo'],
['foo', '[nameSpan] foo'],
['', ''],
['void bar', 'void bar'],
['bar', 'bar'],
['bar', '[nameSpan] bar'],
['', ' '],
]);
});

it('should record span for a regex without flags', () => {
const ast = parseBinding('/^http:\\/\\/foo\\.bar/');
expect(unparseWithSpan(ast)).toContain([
Expand Down