move some stuff around

pull/16268/head
Rich Harris 3 months ago
parent 73b77cc744
commit ab823c8ffa

@ -20,9 +20,8 @@ export { default as preprocess } from './preprocess/index.js';
*/
export function compile(source, options) {
source = remove_bom(source);
state.reset_warning_filter(options.warningFilter);
state.reset_warnings(options.warningFilter);
const validated = validate_component_options(options, '');
state.reset(source, validated);
let parsed = _parse(source);
@ -64,9 +63,8 @@ export function compile(source, options) {
*/
export function compileModule(source, options) {
source = remove_bom(source);
state.reset_warning_filter(options.warningFilter);
state.reset_warnings(options.warningFilter);
const validated = validate_module_options(options, '');
state.reset(source, validated);
const analysis = analyze_module(source, validated);
return transform_module(analysis, source, validated);
@ -113,7 +111,7 @@ export function compileModule(source, options) {
*/
export function parse(source, { modern, loose } = {}) {
source = remove_bom(source);
state.reset_warning_filter(() => false);
state.reset_warnings(() => false);
const ast = _parse(source, loose);
return to_public_ast(source, ast, modern);

@ -9,7 +9,7 @@ import { parse } from '../phases/1-parse/index.js';
import { regex_valid_component_name } from '../phases/1-parse/state/element.js';
import { analyze_component } from '../phases/2-analyze/index.js';
import { get_rune } from '../phases/scope.js';
import { reset, reset_warning_filter } from '../state.js';
import { reset, reset_warnings } from '../state.js';
import {
extract_identifiers,
extract_all_identifiers_from_expression,
@ -134,8 +134,8 @@ export function migrate(source, { filename, use_ts } = {}) {
return start + style_placeholder + end;
});
reset_warning_filter(() => false);
reset(source, { filename: filename ?? '(unknown)' });
reset_warnings(() => false);
reset({ filename: filename ?? '(unknown)' });
let parsed = parse(source);

@ -76,6 +76,7 @@ import { UseDirective } from './visitors/UseDirective.js';
import { VariableDeclarator } from './visitors/VariableDeclarator.js';
import is_reference from 'is-reference';
import { mark_subtree_dynamic } from './visitors/shared/fragment.js';
import * as state from '../../state.js';
/**
* @type {Visitors}
@ -240,6 +241,7 @@ export function analyze_module(source, options) {
/** @type {AST.JSComment[]} */
const comments = [];
state.set_source(source);
const ast = parse(source, comments, false, false);
const { scope, scopes } = create_scopes(ast, new ScopeRoot(), false, null);
@ -269,6 +271,8 @@ export function analyze_module(source, options) {
classes: new Map()
};
state.reset(options);
walk(
/** @type {Node} */ (ast),
{
@ -506,6 +510,8 @@ export function analyze_component(root, source, options) {
snippets: new Set()
};
state.reset(options);
if (!runes) {
// every exported `let` or `var` declaration becomes a prop, everything else becomes an export
for (const node of instance.ast.body) {

@ -77,8 +77,9 @@ export function pop_ignore() {
*
* @param {(warning: Warning) => boolean} fn
*/
export function reset_warning_filter(fn = () => true) {
export function reset_warnings(fn = () => true) {
warning_filter = fn;
warnings = [];
}
/**
@ -91,11 +92,9 @@ export function is_ignored(node, code) {
}
/**
* @param {string} _source
* @param {{ dev?: boolean; filename: string; rootDir?: string }} options
*/
export function reset(_source, options) {
source = _source;
export function reset(options) {
const root_dir = options.rootDir?.replace(/\\/g, '/');
filename = options.filename.replace(/\\/g, '/');
@ -106,8 +105,6 @@ export function reset(_source, options) {
filename = filename.replace(root_dir, '').replace(/^[/\\]/, '');
}
set_source(source);
warnings = [];
ignore_stack = [];
ignore_map.clear();
}

Loading…
Cancel
Save