@wuchale/svelte 0.17.6 → 0.17.7

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.
@@ -41,6 +41,6 @@ export declare class SvelteTransformer extends Transformer {
41
41
  visitSv: (node: AST.SvelteNode | AnyNode) => Message[];
42
42
  /** collects the ranges that will be checked if a snippet identifier is exported using RegExp test to simplify */
43
43
  collectModuleExportRanges: (script: AST.Script) => void;
44
- transformSv: () => TransformOutput;
44
+ transformSv: () => Promise<TransformOutput>;
45
45
  }
46
46
  export {};
@@ -1,5 +1,5 @@
1
1
  import MagicString from "magic-string";
2
- import { parse } from "svelte/compiler";
2
+ import { parse, preprocess } from "svelte/compiler";
3
3
  import { Message } from 'wuchale';
4
4
  import { Transformer, parseScript } from 'wuchale/adapter-vanilla';
5
5
  import { MixedVisitor, nonWhitespaceText, processCommentDirectives, varNames } from "wuchale/adapter-utils";
@@ -7,6 +7,16 @@ const nodesWithChildren = ['RegularElement', 'Component'];
7
7
  const rtComponent = 'W_tx_';
8
8
  const snipPrefix = '_w_snippet_';
9
9
  const rtModuleVar = varNames.rt + 'mod_';
10
+ // for use before actually parsing the code,
11
+ // to remove the contents of e.g. <style lang="scss">
12
+ // without messing up indices for magic-string
13
+ const removeSCSS = ({ attributes, content }) => {
14
+ if (attributes.lang) {
15
+ return {
16
+ code: ' '.repeat(content.length),
17
+ };
18
+ }
19
+ };
10
20
  export class SvelteTransformer extends Transformer {
11
21
  // state
12
22
  currentElement;
@@ -330,11 +340,12 @@ export class SvelteTransformer extends Transformer {
330
340
  }
331
341
  }
332
342
  };
333
- transformSv = () => {
343
+ transformSv = async () => {
334
344
  const isComponent = this.filename.endsWith('.svelte');
335
345
  let ast;
336
346
  if (isComponent) {
337
- ast = parse(this.content, { modern: true });
347
+ const prepd = await preprocess(this.content, { style: removeSCSS });
348
+ ast = parse(prepd.code, { modern: true });
338
349
  }
339
350
  else {
340
351
  const [pAst, comments] = parseScript(this.content);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/svelte",
3
- "version": "0.17.6",
3
+ "version": "0.17.7",
4
4
  "description": "Protobuf-like i18n from plain code: Svelte adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -52,7 +52,7 @@
52
52
  "license": "MIT",
53
53
  "dependencies": {
54
54
  "svelte": "^5.37.0",
55
- "wuchale": "^0.18.6"
55
+ "wuchale": "^0.18.7"
56
56
  },
57
57
  "devDependencies": {
58
58
  "acorn": "^8.15.0",