Merge pull request #1789 from sveltejs/gh-1788

adjust parsing of directives to preserve line/column info
pull/1792/head
Rich Harris 6 years ago committed by GitHub
commit 9395573db5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,4 @@
import { parseExpressionAt } from 'acorn';
import repeat from '../../utils/repeat';
import { Parser } from '../index';
const DIRECTIVES: Record<string, {
@ -101,35 +100,26 @@ Object.keys(DIRECTIVES).forEach(name => {
});
function readExpression(parser: Parser, start: number, quoteMark: string|null) {
let str = '';
let i = start;
let escaped = false;
for (let i = start; i < parser.template.length; i += 1) {
for (; i < parser.template.length; i += 1) {
const char = parser.template[i];
if (quoteMark) {
if (char === quoteMark) {
if (escaped) {
str += quoteMark;
} else {
break;
}
if (!escaped) break;
} else if (escaped) {
str += '\\' + char;
escaped = false;
} else if (char === '\\') {
escaped = true;
} else {
str += char;
}
} else if (/[\s\/>]/.test(char)) {
break;
} else {
str += char;
}
}
const expression = parseExpressionAt(repeat(' ', start) + str, start, {
const expression = parseExpressionAt(parser.template.slice(0, i), start, {
ecmaVersion: 9,
});
parser.index = expression.end;

Loading…
Cancel
Save