@intlayer/svelte-compiler 8.6.9 → 8.7.0-canary.0

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.
@@ -0,0 +1,48 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/extractSvelteFieldUsage.ts
4
+ /**
5
+ * Extracts intlayer dictionary field usage from a Svelte SFC for a set of
6
+ * plain variable bindings (i.e. `const content = useIntlayer('key')`).
7
+ *
8
+ * Svelte's `useIntlayer` returns a Svelte store. Inside both the `<script>`
9
+ * block and the `<template>`, stores are consumed via the auto-subscription
10
+ * prefix `$` — so `const bm = useIntlayer('benchmark')` is accessed as
11
+ * `$bm.fieldName`.
12
+ *
13
+ * Because Svelte's `$store` syntax is preprocessed before standard JS tools
14
+ * see the file, static Babel-scope analysis cannot link `$bm` back to `bm`.
15
+ * This module fills that gap by running a targeted regex over the raw source.
16
+ */
17
+ /** Escapes special regex characters in a string used as a regex literal. */
18
+ const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
19
+ /**
20
+ * Analyzes a Svelte SFC source string and returns the top-level content field
21
+ * names that are statically accessed for each plain intlayer variable binding.
22
+ *
23
+ * Matches the Svelte reactive store access pattern `$varName.fieldName`
24
+ * throughout the entire file (both `<script>` and markup regions).
25
+ *
26
+ * @param code - Full `.svelte` file source.
27
+ * @param plainVariables - List of plain variable bindings to analyse.
28
+ * @returns Map from dictionary key to the set of accessed top-level field names.
29
+ * If no fields can be determined for a given key it is omitted from the
30
+ * map so the caller can fall back to `'all'`.
31
+ */
32
+ const extractSvelteIntlayerFieldUsage = (code, plainVariables) => {
33
+ const result = /* @__PURE__ */ new Map();
34
+ if (plainVariables.length === 0) return result;
35
+ for (const { variableName, dictionaryKey } of plainVariables) {
36
+ const fields = /* @__PURE__ */ new Set();
37
+ const esc = escapeRegExp(variableName);
38
+ const storeRe = new RegExp(`(?<![\\w$])\\$${esc}\\.(\\w+)`, "g");
39
+ storeRe.lastIndex = 0;
40
+ for (let m = storeRe.exec(code); m !== null; m = storeRe.exec(code)) fields.add(m[1]);
41
+ if (fields.size > 0) result.set(dictionaryKey, fields);
42
+ }
43
+ return result;
44
+ };
45
+
46
+ //#endregion
47
+ exports.extractSvelteIntlayerFieldUsage = extractSvelteIntlayerFieldUsage;
48
+ //# sourceMappingURL=extractSvelteFieldUsage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractSvelteFieldUsage.cjs","names":[],"sources":["../../src/extractSvelteFieldUsage.ts"],"sourcesContent":["/**\n * Extracts intlayer dictionary field usage from a Svelte SFC for a set of\n * plain variable bindings (i.e. `const content = useIntlayer('key')`).\n *\n * Svelte's `useIntlayer` returns a Svelte store. Inside both the `<script>`\n * block and the `<template>`, stores are consumed via the auto-subscription\n * prefix `$` — so `const bm = useIntlayer('benchmark')` is accessed as\n * `$bm.fieldName`.\n *\n * Because Svelte's `$store` syntax is preprocessed before standard JS tools\n * see the file, static Babel-scope analysis cannot link `$bm` back to `bm`.\n * This module fills that gap by running a targeted regex over the raw source.\n */\n\n/** Escapes special regex characters in a string used as a regex literal. */\nconst escapeRegExp = (str: string): string =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** Input descriptor for a single plain variable binding. */\nexport type PlainVariableInfo = {\n /** The local variable name in the script (`bm` in `const bm = useIntlayer(…)`). */\n variableName: string;\n /** The intlayer dictionary key passed to `useIntlayer`. */\n dictionaryKey: string;\n};\n\n/**\n * Analyzes a Svelte SFC source string and returns the top-level content field\n * names that are statically accessed for each plain intlayer variable binding.\n *\n * Matches the Svelte reactive store access pattern `$varName.fieldName`\n * throughout the entire file (both `<script>` and markup regions).\n *\n * @param code - Full `.svelte` file source.\n * @param plainVariables - List of plain variable bindings to analyse.\n * @returns Map from dictionary key to the set of accessed top-level field names.\n * If no fields can be determined for a given key it is omitted from the\n * map so the caller can fall back to `'all'`.\n */\nexport const extractSvelteIntlayerFieldUsage = (\n code: string,\n plainVariables: PlainVariableInfo[]\n): Map<string, Set<string>> => {\n const result = new Map<string, Set<string>>();\n\n if (plainVariables.length === 0) return result;\n\n for (const { variableName, dictionaryKey } of plainVariables) {\n const fields = new Set<string>();\n const esc = escapeRegExp(variableName);\n\n // Svelte store auto-subscription: $varName.fieldName\n // The `$` must be preceded by a word boundary or the start of the\n // expression (not an identifier character) to avoid false positives such\n // as matching `$$bm.field` or `_$bm.field`.\n const storeRe = new RegExp(`(?<![\\\\w$])\\\\$${esc}\\\\.(\\\\w+)`, 'g');\n\n storeRe.lastIndex = 0;\n for (let m = storeRe.exec(code); m !== null; m = storeRe.exec(code)) {\n fields.add(m[1]);\n }\n\n if (fields.size > 0) {\n result.set(dictionaryKey, fields);\n }\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,MAAM,gBAAgB,QACpB,IAAI,QAAQ,uBAAuB,OAAO;;;;;;;;;;;;;;AAuB5C,MAAa,mCACX,MACA,mBAC6B;CAC7B,MAAM,yBAAS,IAAI,KAA0B;AAE7C,KAAI,eAAe,WAAW,EAAG,QAAO;AAExC,MAAK,MAAM,EAAE,cAAc,mBAAmB,gBAAgB;EAC5D,MAAM,yBAAS,IAAI,KAAa;EAChC,MAAM,MAAM,aAAa,aAAa;EAMtC,MAAM,UAAU,IAAI,OAAO,iBAAiB,IAAI,YAAY,IAAI;AAEhE,UAAQ,YAAY;AACpB,OAAK,IAAI,IAAI,QAAQ,KAAK,KAAK,EAAE,MAAM,MAAM,IAAI,QAAQ,KAAK,KAAK,CACjE,QAAO,IAAI,EAAE,GAAG;AAGlB,MAAI,OAAO,OAAO,EAChB,QAAO,IAAI,eAAe,OAAO;;AAIrC,QAAO"}
@@ -1,6 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_svelte_intlayer_extract = require('./svelte-intlayer-extract.cjs');
3
+ const require_extractSvelteFieldUsage = require('./extractSvelteFieldUsage.cjs');
3
4
 
5
+ exports.extractSvelteIntlayerFieldUsage = require_extractSvelteFieldUsage.extractSvelteIntlayerFieldUsage;
4
6
  exports.intlayerSvelteExtract = require_svelte_intlayer_extract.intlayerSvelteExtract;
5
7
  exports.processSvelteFile = require_svelte_intlayer_extract.processSvelteFile;
6
8
  exports.shouldProcessFile = require_svelte_intlayer_extract.shouldProcessFile;
@@ -0,0 +1,46 @@
1
+ //#region src/extractSvelteFieldUsage.ts
2
+ /**
3
+ * Extracts intlayer dictionary field usage from a Svelte SFC for a set of
4
+ * plain variable bindings (i.e. `const content = useIntlayer('key')`).
5
+ *
6
+ * Svelte's `useIntlayer` returns a Svelte store. Inside both the `<script>`
7
+ * block and the `<template>`, stores are consumed via the auto-subscription
8
+ * prefix `$` — so `const bm = useIntlayer('benchmark')` is accessed as
9
+ * `$bm.fieldName`.
10
+ *
11
+ * Because Svelte's `$store` syntax is preprocessed before standard JS tools
12
+ * see the file, static Babel-scope analysis cannot link `$bm` back to `bm`.
13
+ * This module fills that gap by running a targeted regex over the raw source.
14
+ */
15
+ /** Escapes special regex characters in a string used as a regex literal. */
16
+ const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
17
+ /**
18
+ * Analyzes a Svelte SFC source string and returns the top-level content field
19
+ * names that are statically accessed for each plain intlayer variable binding.
20
+ *
21
+ * Matches the Svelte reactive store access pattern `$varName.fieldName`
22
+ * throughout the entire file (both `<script>` and markup regions).
23
+ *
24
+ * @param code - Full `.svelte` file source.
25
+ * @param plainVariables - List of plain variable bindings to analyse.
26
+ * @returns Map from dictionary key to the set of accessed top-level field names.
27
+ * If no fields can be determined for a given key it is omitted from the
28
+ * map so the caller can fall back to `'all'`.
29
+ */
30
+ const extractSvelteIntlayerFieldUsage = (code, plainVariables) => {
31
+ const result = /* @__PURE__ */ new Map();
32
+ if (plainVariables.length === 0) return result;
33
+ for (const { variableName, dictionaryKey } of plainVariables) {
34
+ const fields = /* @__PURE__ */ new Set();
35
+ const esc = escapeRegExp(variableName);
36
+ const storeRe = new RegExp(`(?<![\\w$])\\$${esc}\\.(\\w+)`, "g");
37
+ storeRe.lastIndex = 0;
38
+ for (let m = storeRe.exec(code); m !== null; m = storeRe.exec(code)) fields.add(m[1]);
39
+ if (fields.size > 0) result.set(dictionaryKey, fields);
40
+ }
41
+ return result;
42
+ };
43
+
44
+ //#endregion
45
+ export { extractSvelteIntlayerFieldUsage };
46
+ //# sourceMappingURL=extractSvelteFieldUsage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractSvelteFieldUsage.mjs","names":[],"sources":["../../src/extractSvelteFieldUsage.ts"],"sourcesContent":["/**\n * Extracts intlayer dictionary field usage from a Svelte SFC for a set of\n * plain variable bindings (i.e. `const content = useIntlayer('key')`).\n *\n * Svelte's `useIntlayer` returns a Svelte store. Inside both the `<script>`\n * block and the `<template>`, stores are consumed via the auto-subscription\n * prefix `$` — so `const bm = useIntlayer('benchmark')` is accessed as\n * `$bm.fieldName`.\n *\n * Because Svelte's `$store` syntax is preprocessed before standard JS tools\n * see the file, static Babel-scope analysis cannot link `$bm` back to `bm`.\n * This module fills that gap by running a targeted regex over the raw source.\n */\n\n/** Escapes special regex characters in a string used as a regex literal. */\nconst escapeRegExp = (str: string): string =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** Input descriptor for a single plain variable binding. */\nexport type PlainVariableInfo = {\n /** The local variable name in the script (`bm` in `const bm = useIntlayer(…)`). */\n variableName: string;\n /** The intlayer dictionary key passed to `useIntlayer`. */\n dictionaryKey: string;\n};\n\n/**\n * Analyzes a Svelte SFC source string and returns the top-level content field\n * names that are statically accessed for each plain intlayer variable binding.\n *\n * Matches the Svelte reactive store access pattern `$varName.fieldName`\n * throughout the entire file (both `<script>` and markup regions).\n *\n * @param code - Full `.svelte` file source.\n * @param plainVariables - List of plain variable bindings to analyse.\n * @returns Map from dictionary key to the set of accessed top-level field names.\n * If no fields can be determined for a given key it is omitted from the\n * map so the caller can fall back to `'all'`.\n */\nexport const extractSvelteIntlayerFieldUsage = (\n code: string,\n plainVariables: PlainVariableInfo[]\n): Map<string, Set<string>> => {\n const result = new Map<string, Set<string>>();\n\n if (plainVariables.length === 0) return result;\n\n for (const { variableName, dictionaryKey } of plainVariables) {\n const fields = new Set<string>();\n const esc = escapeRegExp(variableName);\n\n // Svelte store auto-subscription: $varName.fieldName\n // The `$` must be preceded by a word boundary or the start of the\n // expression (not an identifier character) to avoid false positives such\n // as matching `$$bm.field` or `_$bm.field`.\n const storeRe = new RegExp(`(?<![\\\\w$])\\\\$${esc}\\\\.(\\\\w+)`, 'g');\n\n storeRe.lastIndex = 0;\n for (let m = storeRe.exec(code); m !== null; m = storeRe.exec(code)) {\n fields.add(m[1]);\n }\n\n if (fields.size > 0) {\n result.set(dictionaryKey, fields);\n }\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAM,gBAAgB,QACpB,IAAI,QAAQ,uBAAuB,OAAO;;;;;;;;;;;;;;AAuB5C,MAAa,mCACX,MACA,mBAC6B;CAC7B,MAAM,yBAAS,IAAI,KAA0B;AAE7C,KAAI,eAAe,WAAW,EAAG,QAAO;AAExC,MAAK,MAAM,EAAE,cAAc,mBAAmB,gBAAgB;EAC5D,MAAM,yBAAS,IAAI,KAAa;EAChC,MAAM,MAAM,aAAa,aAAa;EAMtC,MAAM,UAAU,IAAI,OAAO,iBAAiB,IAAI,YAAY,IAAI;AAEhE,UAAQ,YAAY;AACpB,OAAK,IAAI,IAAI,QAAQ,KAAK,KAAK,EAAE,MAAM,MAAM,IAAI,QAAQ,KAAK,KAAK,CACjE,QAAO,IAAI,EAAE,GAAG;AAGlB,MAAI,OAAO,OAAO,EAChB,QAAO,IAAI,eAAe,OAAO;;AAIrC,QAAO"}
@@ -1,3 +1,4 @@
1
1
  import { intlayerSvelteExtract, processSvelteFile, shouldProcessFile } from "./svelte-intlayer-extract.mjs";
2
+ import { extractSvelteIntlayerFieldUsage } from "./extractSvelteFieldUsage.mjs";
2
3
 
3
- export { intlayerSvelteExtract, processSvelteFile, shouldProcessFile };
4
+ export { extractSvelteIntlayerFieldUsage, intlayerSvelteExtract, processSvelteFile, shouldProcessFile };
@@ -0,0 +1,36 @@
1
+ //#region src/extractSvelteFieldUsage.d.ts
2
+ /**
3
+ * Extracts intlayer dictionary field usage from a Svelte SFC for a set of
4
+ * plain variable bindings (i.e. `const content = useIntlayer('key')`).
5
+ *
6
+ * Svelte's `useIntlayer` returns a Svelte store. Inside both the `<script>`
7
+ * block and the `<template>`, stores are consumed via the auto-subscription
8
+ * prefix `$` — so `const bm = useIntlayer('benchmark')` is accessed as
9
+ * `$bm.fieldName`.
10
+ *
11
+ * Because Svelte's `$store` syntax is preprocessed before standard JS tools
12
+ * see the file, static Babel-scope analysis cannot link `$bm` back to `bm`.
13
+ * This module fills that gap by running a targeted regex over the raw source.
14
+ */
15
+ /** Input descriptor for a single plain variable binding. */
16
+ type PlainVariableInfo = {
17
+ /** The local variable name in the script (`bm` in `const bm = useIntlayer(…)`). */variableName: string; /** The intlayer dictionary key passed to `useIntlayer`. */
18
+ dictionaryKey: string;
19
+ };
20
+ /**
21
+ * Analyzes a Svelte SFC source string and returns the top-level content field
22
+ * names that are statically accessed for each plain intlayer variable binding.
23
+ *
24
+ * Matches the Svelte reactive store access pattern `$varName.fieldName`
25
+ * throughout the entire file (both `<script>` and markup regions).
26
+ *
27
+ * @param code - Full `.svelte` file source.
28
+ * @param plainVariables - List of plain variable bindings to analyse.
29
+ * @returns Map from dictionary key to the set of accessed top-level field names.
30
+ * If no fields can be determined for a given key it is omitted from the
31
+ * map so the caller can fall back to `'all'`.
32
+ */
33
+ declare const extractSvelteIntlayerFieldUsage: (code: string, plainVariables: PlainVariableInfo[]) => Map<string, Set<string>>;
34
+ //#endregion
35
+ export { PlainVariableInfo, extractSvelteIntlayerFieldUsage };
36
+ //# sourceMappingURL=extractSvelteFieldUsage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractSvelteFieldUsage.d.ts","names":[],"sources":["../../src/extractSvelteFieldUsage.ts"],"mappings":";;AAmBA;;;;;AAoBA;;;;;;;;KApBY,iBAAA;EAsBM,mFApBhB,YAAA,UAqBC;EAnBD,aAAA;AAAA;;;;;;;;;;;;;;cAgBW,+BAAA,GACX,IAAA,UACA,cAAA,EAAgB,iBAAA,OACf,GAAA,SAAY,GAAA"}
@@ -1,2 +1,3 @@
1
+ import { PlainVariableInfo, extractSvelteIntlayerFieldUsage } from "./extractSvelteFieldUsage.js";
1
2
  import { ExtractPluginOptions, ExtractResult, ExtractedContent, intlayerSvelteExtract, processSvelteFile, shouldProcessFile } from "./svelte-intlayer-extract.js";
2
- export { type ExtractPluginOptions, type ExtractResult, type ExtractedContent, intlayerSvelteExtract, processSvelteFile, shouldProcessFile };
3
+ export { type ExtractPluginOptions, type ExtractResult, type ExtractedContent, type PlainVariableInfo, extractSvelteIntlayerFieldUsage, intlayerSvelteExtract, processSvelteFile, shouldProcessFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/svelte-compiler",
3
- "version": "8.6.9",
3
+ "version": "8.7.0-canary.0",
4
4
  "private": false,
5
5
  "description": "Vite-compatible compiler plugin for Svelte with Intlayer, providing HMR support, file transformation, and optimized dictionary loading for Svelte applications.",
6
6
  "keywords": [
@@ -81,13 +81,13 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "@babel/core": "7.29.0",
84
- "@intlayer/types": "8.6.9",
84
+ "@intlayer/types": "8.7.0-canary.0",
85
85
  "fast-glob": "3.3.3",
86
86
  "magic-string": "0.30.21"
87
87
  },
88
88
  "devDependencies": {
89
- "@intlayer/config": "8.6.9",
90
- "@intlayer/types": "8.6.9",
89
+ "@intlayer/config": "8.7.0-canary.0",
90
+ "@intlayer/types": "8.7.0-canary.0",
91
91
  "@types/babel__core": "7.20.5",
92
92
  "@types/babel__generator": "7.27.0",
93
93
  "@types/babel__traverse": "7.28.0",
@@ -98,7 +98,7 @@
98
98
  "rimraf": "6.1.3",
99
99
  "tsdown": "0.21.7",
100
100
  "typescript": "6.0.2",
101
- "vitest": "4.1.2"
101
+ "vitest": "4.1.3"
102
102
  },
103
103
  "peerDependencies": {
104
104
  "@babel/core": ">=6.0.0",