Skip to content

Commit 085b7f6

Browse files
committed
fix
1 parent b05318e commit 085b7f6

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

packages/svelte/scripts/process-messages/templates/compile-warnings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { warnings, ignore_stack, ignore_map, filter_warning } from './state.js';
1+
import { warnings, ignore_stack, ignore_map, warning_filter } from './state.js';
22
import { CompileDiagnostic } from './utils/compile_diagnostic.js';
33

44
/** @typedef {{ start?: number, end?: number }} NodeLike */
@@ -34,7 +34,7 @@ function w(node, code, message) {
3434
node && node.start !== undefined ? [node.start, node.end ?? node.start] : undefined
3535
);
3636

37-
if (!filter_warning(warning)) return;
37+
if (!warning_filter(warning)) return;
3838

3939
warnings.push(warning);
4040
}

packages/svelte/src/compiler/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export { default as preprocess } from './preprocess/index.js';
2020
* @returns {CompileResult}
2121
*/
2222
export function compile(source, options) {
23+
state.reset_warning_filter(options.warningFilter);
2324
const validated = validate_component_options(options, '');
2425
state.reset(source, validated);
2526

@@ -58,6 +59,7 @@ export function compile(source, options) {
5859
* @returns {CompileResult}
5960
*/
6061
export function compileModule(source, options) {
62+
state.reset_warning_filter(options.warningFilter);
6163
const validated = validate_module_options(options, '');
6264
state.reset(source, validated);
6365

@@ -103,6 +105,7 @@ export function compileModule(source, options) {
103105
* @returns {Root | LegacyRoot}
104106
*/
105107
export function parse(source, { filename, rootDir, modern } = {}) {
108+
state.reset_warning_filter(() => false);
106109
state.reset(source, { filename, rootDir }); // TODO it's weird to require filename/rootDir here. reconsider the API
107110

108111
const ast = _parse(source);

packages/svelte/src/compiler/migrate/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { parse } from '../phases/1-parse/index.js';
1010
import { analyze_component } from '../phases/2-analyze/index.js';
1111
import { validate_component_options } from '../validate-options.js';
1212
import { get_rune } from '../phases/scope.js';
13-
import { reset } from '../state.js';
13+
import { reset, reset_warning_filter } from '../state.js';
1414
import { extract_identifiers } from '../utils/ast.js';
1515
import { regex_is_valid_identifier } from '../phases/patterns.js';
1616
import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js';
@@ -24,6 +24,7 @@ import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js';
2424
*/
2525
export function migrate(source) {
2626
try {
27+
reset_warning_filter(() => false);
2728
reset(source, { filename: 'migrate.svelte' });
2829

2930
let parsed = parse(source);

packages/svelte/src/compiler/state.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,17 @@ export function pop_ignore() {
5151
ignore_stack.pop();
5252
}
5353

54+
/**
55+
*
56+
* @param {(warning: Warning) => boolean} fn
57+
*/
58+
export function reset_warning_filter(fn = () => true) {
59+
warning_filter = fn;
60+
}
61+
5462
/**
5563
* @param {string} _source
56-
* @param {{ filename?: string, rootDir?: string, warningFilter?: CompileOptions['warningFilter'] }} options
64+
* @param {{ filename?: string, rootDir?: string }} options
5765
*/
5866
export function reset(_source, options) {
5967
source = _source;
@@ -70,7 +78,6 @@ export function reset(_source, options) {
7078
}
7179

7280
locator = getLocator(source, { offsetLine: 1 });
73-
warning_filter = options.warningFilter ?? (() => true);
7481
warnings = [];
7582
ignore_stack = [];
7683
ignore_map.clear();

packages/svelte/src/compiler/warnings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,4 +744,4 @@ export function slot_element_deprecated(node) {
744744
*/
745745
export function svelte_element_invalid_this(node) {
746746
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");
747-
}
747+
}

0 commit comments

Comments
 (0)