pull/12296/head
Rich Harris 2 years ago
parent b05318e05b
commit 085b7f60a4

@ -1,4 +1,4 @@
import { warnings, ignore_stack, ignore_map, filter_warning } from './state.js';
import { warnings, ignore_stack, ignore_map, warning_filter } from './state.js';
import { CompileDiagnostic } from './utils/compile_diagnostic.js';
/** @typedef {{ start?: number, end?: number }} NodeLike */
@ -34,7 +34,7 @@ function w(node, code, message) {
node && node.start !== undefined ? [node.start, node.end ?? node.start] : undefined
);
if (!filter_warning(warning)) return;
if (!warning_filter(warning)) return;
warnings.push(warning);
}

@ -20,6 +20,7 @@ export { default as preprocess } from './preprocess/index.js';
* @returns {CompileResult}
*/
export function compile(source, options) {
state.reset_warning_filter(options.warningFilter);
const validated = validate_component_options(options, '');
state.reset(source, validated);
@ -58,6 +59,7 @@ export function compile(source, options) {
* @returns {CompileResult}
*/
export function compileModule(source, options) {
state.reset_warning_filter(options.warningFilter);
const validated = validate_module_options(options, '');
state.reset(source, validated);
@ -103,6 +105,7 @@ export function compileModule(source, options) {
* @returns {Root | LegacyRoot}
*/
export function parse(source, { filename, rootDir, modern } = {}) {
state.reset_warning_filter(() => false);
state.reset(source, { filename, rootDir }); // TODO it's weird to require filename/rootDir here. reconsider the API
const ast = _parse(source);

@ -10,7 +10,7 @@ import { parse } from '../phases/1-parse/index.js';
import { analyze_component } from '../phases/2-analyze/index.js';
import { validate_component_options } from '../validate-options.js';
import { get_rune } from '../phases/scope.js';
import { reset } from '../state.js';
import { reset, reset_warning_filter } from '../state.js';
import { extract_identifiers } from '../utils/ast.js';
import { regex_is_valid_identifier } from '../phases/patterns.js';
import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js';
@ -24,6 +24,7 @@ import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js';
*/
export function migrate(source) {
try {
reset_warning_filter(() => false);
reset(source, { filename: 'migrate.svelte' });
let parsed = parse(source);

@ -51,9 +51,17 @@ export function pop_ignore() {
ignore_stack.pop();
}
/**
*
* @param {(warning: Warning) => boolean} fn
*/
export function reset_warning_filter(fn = () => true) {
warning_filter = fn;
}
/**
* @param {string} _source
* @param {{ filename?: string, rootDir?: string, warningFilter?: CompileOptions['warningFilter'] }} options
* @param {{ filename?: string, rootDir?: string }} options
*/
export function reset(_source, options) {
source = _source;
@ -70,7 +78,6 @@ export function reset(_source, options) {
}
locator = getLocator(source, { offsetLine: 1 });
warning_filter = options.warningFilter ?? (() => true);
warnings = [];
ignore_stack = [];
ignore_map.clear();

@ -744,4 +744,4 @@ export function slot_element_deprecated(node) {
*/
export function svelte_element_invalid_this(node) {
w(node, "svelte_element_invalid_this", "`this` should be an `{expression}`. Using a string attribute value will cause an error in future versions of Svelte");
}
}
Loading…
Cancel
Save