@rusveltejs/compiler 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/compiler.js +31 -21
  2. package/package.json +7 -7
package/compiler.js CHANGED
@@ -215,20 +215,38 @@ export async function create(real, real_url) {
215
215
  return result;
216
216
  }
217
217
 
218
- /** `state` as compile leaves it, so `CompileDiagnostic` fills in filename, start/end, frame */
219
- function set_state(source, options, runes) {
218
+ /**
219
+ * The result's warnings, made the way compile makes them: `state` is reset, the options are
220
+ * validated by the installed compiler (its deprecation warnings, once per instance), the
221
+ * warnings emitted before the analysis calls `state.adjust` are made with the filename as
222
+ * given, and the rest with the filename relative to `rootDir`. `CompileDiagnostic` fills in
223
+ * filename, start/end and frame from `state`. Returns null if the validation throws.
224
+ * @param {boolean} module
225
+ */
226
+ function warnings_of(source, options, result, module) {
220
227
  state.reset({ warning: options.warningFilter, filename: options.filename });
221
228
  state.set_source(source);
222
- state.adjust({ dev: !!options.dev, rootDir: options.rootDir ?? process.cwd(), runes });
223
- }
224
-
225
- function warnings_of(result, options) {
229
+ if (!module) {
230
+ try {
231
+ validate_component_options(options, '');
232
+ } catch {
233
+ return null;
234
+ }
235
+ }
236
+ const out = [...state.warnings];
226
237
  const filter = options.warningFilter ?? (() => true);
227
- const out = [];
228
- for (const w of result.warnings) {
229
- if (w.code.startsWith('options_deprecated_')) continue;
238
+ const early = result.earlyWarnings ?? 0;
239
+ result.warnings.forEach((w, i) => {
240
+ if (i === early) {
241
+ state.adjust({ dev: !!options.dev, rootDir: options.rootDir ?? process.cwd(), runes: result.runes ?? true });
242
+ }
243
+ // the deprecation warnings come from the validation above
244
+ if (w.code.startsWith('options_deprecated_')) return;
230
245
  const warning = new CompileWarning(w.code, w.message, w.position ?? undefined);
231
246
  if (filter(warning)) out.push(warning);
247
+ });
248
+ if (result.warnings.length <= early) {
249
+ state.adjust({ dev: !!options.dev, rootDir: options.rootDir ?? process.cwd(), runes: result.runes ?? true });
232
250
  }
233
251
  return out;
234
252
  }
@@ -268,15 +286,8 @@ export async function create(real, real_url) {
268
286
  source = remove_bom(source);
269
287
  const result = run(source, options, false);
270
288
  if (!result) return real.compile(source, options);
271
- set_state(source, options, result.runes);
272
- // the option warnings (deprecated options) come from the installed compiler's own
273
- // validation, so its once-per-instance memory and the warning filter apply as in compile
274
- try {
275
- validate_component_options(options, '');
276
- } catch {
277
- return real.compile(source, options);
278
- }
279
- const option_warnings = [...state.warnings];
289
+ const warnings = warnings_of(source, options, result, false);
290
+ if (!warnings) return real.compile(source, options);
280
291
  // `validate_component_options` defaults the filename
281
292
  options = { ...options, filename: options.filename ?? '(unknown)' };
282
293
 
@@ -299,7 +310,6 @@ export async function create(real, real_url) {
299
310
  merge_with_preprocessor_map(css, options, css.map.sources[0]);
300
311
  }
301
312
 
302
- const warnings = [...option_warnings, ...warnings_of(result, options)];
303
313
  let ast;
304
314
  const compiled = {
305
315
  js,
@@ -331,13 +341,13 @@ export async function create(real, real_url) {
331
341
  source = remove_bom(source);
332
342
  const result = run(source, options, true);
333
343
  if (!result) return real.compileModule(source, options);
334
- set_state(source, options, true);
344
+ const warnings = warnings_of(source, options, result, true);
335
345
  options = { ...options, filename: options.filename ?? '(unknown)' };
336
346
  const js_source_name = get_source_name(options.filename, undefined, 'input.svelte.js');
337
347
  const compiled = {
338
348
  js: { code: result.js.code, map: new JsSourceMap(result.js.mappings, js_source_name, source) },
339
349
  css: null,
340
- warnings: warnings_of(result, options),
350
+ warnings,
341
351
  metadata: { runes: true },
342
352
  ast: null
343
353
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rusveltejs/compiler",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "The Svelte 5 compiler ported to Rust, as a drop-in for svelte/compiler in Vite builds",
5
5
  "keywords": [
6
6
  "svelte",
@@ -40,11 +40,11 @@
40
40
  "svelte": "^5.0.0"
41
41
  },
42
42
  "optionalDependencies": {
43
- "@rusveltejs/darwin-arm64": "0.1.1",
44
- "@rusveltejs/darwin-x64": "0.1.1",
45
- "@rusveltejs/linux-x64-gnu": "0.1.1",
46
- "@rusveltejs/linux-arm64-gnu": "0.1.1",
47
- "@rusveltejs/linux-x64-musl": "0.1.1",
48
- "@rusveltejs/win32-x64-msvc": "0.1.1"
43
+ "@rusveltejs/darwin-arm64": "0.1.2",
44
+ "@rusveltejs/darwin-x64": "0.1.2",
45
+ "@rusveltejs/linux-x64-gnu": "0.1.2",
46
+ "@rusveltejs/linux-arm64-gnu": "0.1.2",
47
+ "@rusveltejs/linux-x64-musl": "0.1.2",
48
+ "@rusveltejs/win32-x64-msvc": "0.1.2"
49
49
  }
50
50
  }