simplify JS parsing step

pull/353/head
Rich-Harris 8 years ago
parent 94dc6d26b6
commit 71cfb93384

@ -1,28 +1,14 @@
import { parse, tokenizer } from 'acorn';
import { parse } from 'acorn';
import spaces from '../../utils/spaces.js';
const scriptClosingTag = '<\/script>';
export default function readScript ( parser, start, attributes ) {
const scriptStart = parser.index;
let scriptEnd = null;
for ( const token of tokenizer( parser.remaining() ) ) {
parser.index = scriptStart + token.end;
parser.allowWhitespace();
scriptEnd = parser.index;
if ( parser.eat( '/script>' ) ) {
// this happens with trailing comments!
scriptEnd -= 1;
break;
}
if ( parser.eat( '<\/script>' ) ) {
break;
}
}
const scriptEnd = parser.template.indexOf( scriptClosingTag, scriptStart );
const source = spaces( scriptStart ) + parser.template.slice( scriptStart, scriptEnd );
parser.index = scriptEnd + scriptClosingTag.length;
let ast;
@ -38,7 +24,6 @@ export default function readScript ( parser, start, attributes ) {
if ( !ast.body.length ) return null;
ast.start = scriptStart;
return {
start,
end: parser.index,

Loading…
Cancel
Save