Skip to content

Commit

Permalink
fix: ts preprocessor - consider store suffixed with number (#461)
Browse files Browse the repository at this point in the history
Fixes sveltejs/svelte#7120

the original regex had +-=, which forgot to escape -, resulting ignoring any characters between + to =
  • Loading branch information
tanhauhau authored Jan 12, 2022
1 parent fbc484a commit a7a94cf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/transformers/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function injectVarsToCode({
// TODO investigate if it's possible to achieve this with a
// TS transformer (previous attemps have failed)
const codestores = Array.from(
contentForCodestores.match(/\$[^\s();:,[\]{}.?!+-=*/\\~|&%<>^`"'°§]+/g) ||
contentForCodestores.match(/\$[^\s();:,[\]{}.?!+\-=*/\\~|&%<>^`"'°§]+/g) ||
[],
(name) => name.slice(1),
).filter((name) => !JAVASCRIPT_RESERVED_KEYWORD_SET.has(name));
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/TypeScriptImports.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Nested from "./Nested.svelte";
import { hello } from "./script";
import { AValue, AType } from "./types";
import { storeTemplateOnly, storeScriptOnly } from "./store";
import { storeTemplateOnly, storeScriptOnly, store0 } from "./store";
import { onlyUsedInModuleScript } from "./modulescript";
const ui = { MyNested: Nested };
const val: AType = "test1";
Expand Down Expand Up @@ -39,6 +39,7 @@
}
$storeScriptOnly;
$storeModuleScriptOnly;
$store0;
// These shouldn't count as store values:
// $\\; $$; $§; $%; $°; $(; $); $[; $]; $<; $>; $ ; $^; $`; $"; $';
Expand Down
2 changes: 1 addition & 1 deletion test/transformers/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('transformer - typescript', () => {
expect(code).toContain(`import { hello } from "./script"`);
expect(code).toContain(`import { AValue } from "./types"`);
expect(code).toContain(
`import { storeTemplateOnly, storeScriptOnly } from "./store"`,
`import { storeTemplateOnly, storeScriptOnly, store0 } from "./store"`,
);
expect(code).toContain(
`import { onlyUsedInModuleScript } from "./modulescript";`,
Expand Down

0 comments on commit a7a94cf

Please sign in to comment.