From 1617547776efc3b23eeaff383dbe33be597ea65f Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 7 Mar 2017 11:21:30 -0500 Subject: [PATCH] simplify JS parsing step --- src/parse/read/script.js | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/parse/read/script.js b/src/parse/read/script.js index 09e1ba9174..641a389804 100644 --- a/src/parse/read/script.js +++ b/src/parse/read/script.js @@ -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,