Skip to content

Commit 6450737

Browse files
committed
add loose option
1 parent a2539cf commit 6450737

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

packages/svelte/src/compiler/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class InternalCompileError extends Error {
1414
*/
1515
constructor(code, message, position) {
1616
super(message);
17-
this.stack = ''; // avoid unnecessary noise; don't set it as a class property or it becomes enumerable
17+
// this.stack = ''; // avoid unnecessary noise; don't set it as a class property or it becomes enumerable
1818
// We want to extend from Error so that various bundler plugins properly handle it.
1919
// But we also want to share the same object shape with that of warnings, therefore
2020
// we create an instance of the shared class an copy over its properties.

packages/svelte/src/compiler/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ export function compileModule(source, options) {
9999
* `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7.
100100
*
101101
* @param {string} source
102-
* @param {{ filename?: string; rootDir?: string; modern?: boolean }} [options]
102+
* @param {{ filename?: string; rootDir?: string; modern?: boolean; loose?: boolean }} [options]
103103
* @returns {AST.Root | LegacyRoot}
104104
*/
105-
export function parse(source, { filename, rootDir, modern } = {}) {
105+
export function parse(source, { filename, rootDir, modern, loose } = {}) {
106106
source = remove_bom(source);
107107
state.reset_warning_filter(() => false);
108108
state.reset(source, { filename: filename ?? '(unknown)', rootDir });
109109

110-
const ast = _parse(source);
110+
const ast = _parse(source, loose);
111111
return to_public_ast(source, ast, modern);
112112
}
113113

packages/svelte/src/compiler/phases/1-parse/index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export class Parser {
2222
*/
2323
template;
2424

25+
/**
26+
* Whether or not we're in loose parsing mode, in which
27+
* case we try to continue parsing as much as possible
28+
* @type {boolean}
29+
*/
30+
loose;
31+
2532
/** */
2633
index = 0;
2734

@@ -43,12 +50,16 @@ export class Parser {
4350
/** @type {LastAutoClosedTag | undefined} */
4451
last_auto_closed_tag;
4552

46-
/** @param {string} template */
47-
constructor(template) {
53+
/**
54+
* @param {string} template
55+
* @param {boolean} loose
56+
*/
57+
constructor(template, loose) {
4858
if (typeof template !== 'string') {
4959
throw new TypeError('Template must be a string');
5060
}
5161

62+
this.loose = loose;
5263
this.template = template.trimEnd();
5364

5465
let match_lang;
@@ -274,10 +285,11 @@ export class Parser {
274285

275286
/**
276287
* @param {string} template
288+
* @param {boolean} [loose]
277289
* @returns {AST.Root}
278290
*/
279-
export function parse(template) {
280-
const parser = new Parser(template);
291+
export function parse(template, loose = false) {
292+
const parser = new Parser(template, loose);
281293
return parser.root;
282294
}
283295

0 commit comments

Comments
 (0)