|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
import { walk as zimmerframe_walk } from 'zimmerframe';
|
|
|
|
|
import { CompileError } from './errors.js';
|
|
|
|
|
import { convert } from './legacy.js';
|
|
|
|
|
import { parse as parse_acorn } from './phases/1-parse/acorn.js';
|
|
|
|
|
import { parse as _parse } from './phases/1-parse/index.js';
|
|
|
|
@ -22,7 +21,6 @@ export function compile(source, options) {
|
|
|
|
|
const validated = validate_component_options(options, '');
|
|
|
|
|
state.reset(source, validated);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let parsed = _parse(source);
|
|
|
|
|
|
|
|
|
|
const { customElement: customElementOptions, ...parsed_options } = parsed.options || {};
|
|
|
|
@ -47,13 +45,6 @@ export function compile(source, options) {
|
|
|
|
|
const result = transform_component(analysis, source, combined_options);
|
|
|
|
|
result.ast = to_public_ast(source, parsed, options.modernAst);
|
|
|
|
|
return result;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (e instanceof CompileError) {
|
|
|
|
|
handle_compile_error(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -68,34 +59,8 @@ export function compileModule(source, options) {
|
|
|
|
|
const validated = validate_module_options(options, '');
|
|
|
|
|
state.reset(source, validated);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const analysis = analyze_module(parse_acorn(source, false), validated);
|
|
|
|
|
const result = transform_module(analysis, source, validated);
|
|
|
|
|
return result;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (e instanceof CompileError) {
|
|
|
|
|
handle_compile_error(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {import('#compiler').CompileError} error
|
|
|
|
|
*/
|
|
|
|
|
function handle_compile_error(error) {
|
|
|
|
|
error.filename = state.filename;
|
|
|
|
|
|
|
|
|
|
if (error.position) {
|
|
|
|
|
const start = state.locator(error.position[0]);
|
|
|
|
|
const end = state.locator(error.position[1]);
|
|
|
|
|
|
|
|
|
|
error.start = start;
|
|
|
|
|
error.end = end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
|
return transform_module(analysis, source, validated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -138,18 +103,7 @@ function handle_compile_error(error) {
|
|
|
|
|
export function parse(source, { filename, rootDir, modern } = {}) {
|
|
|
|
|
state.reset(source, { filename, rootDir }); // TODO it's weird to require filename/rootDir here. reconsider the API
|
|
|
|
|
|
|
|
|
|
/** @type {import('#compiler').Root} */
|
|
|
|
|
let ast;
|
|
|
|
|
try {
|
|
|
|
|
ast = _parse(source);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (e instanceof CompileError) {
|
|
|
|
|
handle_compile_error(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ast = _parse(source);
|
|
|
|
|
return to_public_ast(source, ast, modern);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|