Skip to content

Commit

Permalink
Merge pull request #1789 from sveltejs/gh-1788
Browse files Browse the repository at this point in the history
adjust parsing of directives to preserve line/column info
  • Loading branch information
Rich-Harris authored Oct 20, 2018
2 parents c0ba6fb + b8ed271 commit 9395573
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/parse/read/directives.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { parseExpressionAt } from 'acorn';
import repeat from '../../utils/repeat';
import { Parser } from '../index';

const DIRECTIVES: Record<string, {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9395573

Please sign in to comment.