|
| 1 | +import { isIdentifierStart, isIdentifierChar } from 'acorn'; |
1 | 2 | import { locate, Location } from 'locate-character';
|
2 | 3 | import fragment from './state/fragment';
|
3 | 4 | import { whitespace } from '../utils/patterns';
|
4 | 5 | import { trimStart, trimEnd } from '../utils/trim';
|
5 | 6 | import getCodeFrame from '../utils/getCodeFrame';
|
6 | 7 | import reservedNames from '../utils/reservedNames';
|
| 8 | +import fullCharCodeAt from '../utils/fullCharCodeAt'; |
7 | 9 | import hash from './utils/hash';
|
8 | 10 | import { Node, Parsed } from '../interfaces';
|
9 | 11 | import CompileError from '../utils/CompileError';
|
@@ -147,7 +149,22 @@ export class Parser {
|
147 | 149 |
|
148 | 150 | readIdentifier() {
|
149 | 151 | const start = this.index;
|
150 |
| - const identifier = this.read(/[a-zA-Z_$][a-zA-Z0-9_$]*/); |
| 152 | + |
| 153 | + let i = this.index; |
| 154 | + |
| 155 | + const code = fullCharCodeAt(this.template, i); |
| 156 | + if (!isIdentifierStart(code, true)) return null; |
| 157 | + |
| 158 | + i += code <= 0xffff ? 1 : 2; |
| 159 | + |
| 160 | + while (i < this.template.length) { |
| 161 | + const code = fullCharCodeAt(this.template, i); |
| 162 | + |
| 163 | + if (!isIdentifierChar(code, true)) break; |
| 164 | + i += code <= 0xffff ? 1 : 2; |
| 165 | + } |
| 166 | + |
| 167 | + const identifier = this.template.slice(this.index, this.index = i); |
151 | 168 |
|
152 | 169 | if (reservedNames.has(identifier)) {
|
153 | 170 | this.error(`'${identifier}' is a reserved word in JavaScript and cannot be used here`, start);
|
|
0 commit comments