You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/compiler/parse/read/script.js

40 lines
770 B

import { parse, tokenizer } from 'acorn';
8 years ago
import spaces from '../utils/spaces.js';
8 years ago
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();
if ( parser.eat( '</script>' ) ) {
8 years ago
scriptEnd = scriptStart + token.end;
break;
}
}
const source = spaces( scriptStart ) + parser.template.slice( scriptStart, scriptEnd );
8 years ago
let ast;
try {
ast = parse( source, {
ecmaVersion: 8,
sourceType: 'module'
});
} catch ( err ) {
parser.acornError( err );
}
ast.start = scriptStart;
return {
start,
end: parser.index,
attributes,
content: ast
};
8 years ago
}