@rohal12/spindle 0.64.1 → 0.64.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.64.1",
3
+ "version": "0.64.2",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
@@ -85,7 +85,7 @@
85
85
  },
86
86
  "peerDependencies": {
87
87
  "@rohal12/twee-ts": "^2.0.0",
88
- "happy-dom": ">=20.14.6"
88
+ "happy-dom": ">=21.0.4"
89
89
  },
90
90
  "peerDependenciesMeta": {
91
91
  "@rohal12/twee-ts": {
@@ -108,9 +108,9 @@
108
108
  "@vitest/coverage-v8": "^5.0.3",
109
109
  "codemirror": "^5.65.21",
110
110
  "fake-indexeddb": "^6.2.5",
111
- "fallow": "3.33.1",
111
+ "fallow": "3.34.1",
112
112
  "fast-check": "^4.10.2",
113
- "happy-dom": "^21.0.3",
113
+ "happy-dom": "^21.0.4",
114
114
  "husky": "^9.1.7",
115
115
  "js-yaml": "^5.4.3",
116
116
  "jscpd": "5.4.1",
@@ -8,7 +8,6 @@ import {
8
8
  parameterLookup,
9
9
  macroArgumentLookup,
10
10
  executesRawBody,
11
- usesBuiltinSemantics,
12
11
  type PieceBase,
13
12
  } from './code-check';
14
13
  import { macroArgumentSpans } from './components/macros/macro-args';
@@ -331,7 +331,7 @@ function installSnapshotSvgStyles(
331
331
  let start = 0;
332
332
  let depth = 0;
333
333
  for (let i = 0; i <= rewritten.length; i++) {
334
- const ch = rewritten[i];
334
+ const ch = rewritten.charAt(i);
335
335
  if (ch === '\\') i++;
336
336
  else if (ch === '"' || ch === "'") i = skipString(rewritten, i) - 1;
337
337
  else if (ch === '(' || ch === '[') depth++;
@@ -1,5 +1,5 @@
1
1
  import { useContext, useMemo } from 'preact/hooks';
2
- import { WidgetChildrenContext, renderNodes } from '../../markup/render';
2
+ import { WidgetChildrenContext } from '../../markup/render';
3
3
  import { useMergedLocals } from '../../hooks/use-merged-locals';
4
4
  import { evaluateDisplay } from '../../expression';
5
5
  import { DisplayOnlyContext } from '../../display-only';
@@ -259,3 +259,8 @@ export function splitArgSpans(raw: string): Span[] {
259
259
  export function splitArgs(raw: string): string[] {
260
260
  return splitArgSpans(raw).map(([a, b]) => raw.slice(a, b));
261
261
  }
262
+
263
+ /** `text` as a regular expression source that matches it literally. */
264
+ export function escapeRegExp(text: string): string {
265
+ return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
266
+ }
package/src/index.tsx CHANGED
@@ -25,11 +25,7 @@ import {
25
25
  validateMarkup,
26
26
  type MarkupPassage,
27
27
  } from './markup/validate';
28
- import {
29
- effectiveWidgets,
30
- parseWidgetDef,
31
- type WidgetDefinition,
32
- } from './widgets/widget-def';
28
+ import { effectiveWidgets, type WidgetDefinition } from './widgets/widget-def';
33
29
  import { parseMarkup } from './markup/parse';
34
30
  import { setBlockWidget } from './markup/ast';
35
31
  import { registerWidgetDefinitions } from './widgets/register-widget-def';
@@ -9,6 +9,7 @@
9
9
  * cannot place, it counts as a declaration of unknown value: a parameter, a
10
10
  * pattern, an assignment. Better no answer than another declaration's.
11
11
  */
12
+ import { escapeRegExp } from './components/macros/arg-utils';
12
13
 
13
14
  type Kind = '{' | '(' | '[';
14
15
 
@@ -119,7 +120,7 @@ export class Bindings {
119
120
  properties: ReadonlySet<string>,
120
121
  ): Binding[] {
121
122
  const { code } = this;
122
- const escaped = name.replace(/\$/g, '\\$');
123
+ const escaped = escapeRegExp(name);
123
124
  const bindings: Binding[] = [];
124
125
  for (const m of code.matchAll(
125
126
  new RegExp(`(?<![\\w$])${escaped}(?![\\w$])`, 'g'),
@@ -8,11 +8,11 @@ import {
8
8
  import { isCodeAttribute } from './markup/code-attributes';
9
9
  import { isRawMacro } from './markup/ast';
10
10
  import { errorMessage } from './utils/error-message';
11
+ import { escapeRegExp } from './components/macros/arg-utils';
11
12
  import {
12
13
  CodeSyntaxError,
13
14
  lexJs,
14
15
  readMemberPath,
15
- scanStringLiteral,
16
16
  type JsGoal,
17
17
  type VariableRef,
18
18
  } from './js-lexer';
@@ -89,8 +89,7 @@ export interface VariableSchema extends FieldSchema {
89
89
  }
90
90
 
91
91
  function declarationRegex(sigil: string): RegExp {
92
- const escaped = sigil.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
93
- return new RegExp(`^${escaped}(\\w+)\\s*=\\s*(.+)$`);
92
+ return new RegExp(`^${escapeRegExp(sigil)}(\\w+)\\s*=\\s*(.+)$`);
94
93
  }
95
94
  const VALID_VAR_TYPES = new Set<string>(['number', 'string', 'boolean']);
96
95