@weborigami/language 0.4.2 → 0.5.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.
package/main.js CHANGED
@@ -16,6 +16,5 @@ export { default as jsGlobals } from "./src/runtime/jsGlobals.js";
16
16
  export * as moduleCache from "./src/runtime/moduleCache.js";
17
17
  export { default as OrigamiFiles } from "./src/runtime/OrigamiFiles.js";
18
18
  export * as symbols from "./src/runtime/symbols.js";
19
- export { default as taggedTemplateIndent } from "./src/runtime/templateIndent.js";
20
19
  export { default as TreeEvent } from "./src/runtime/TreeEvent.js";
21
20
  export { default as WatchFilesMixin } from "./src/runtime/WatchFilesMixin.js";
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@weborigami/language",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "Web Origami expression language compiler and runtime",
5
5
  "type": "module",
6
6
  "main": "./main.js",
7
7
  "types": "./index.ts",
8
8
  "devDependencies": {
9
- "@types/node": "22.13.13",
9
+ "@types/node": "24.3.0",
10
10
  "peggy": "4.2.0.",
11
- "typescript": "5.8.2"
11
+ "typescript": "5.9.2"
12
12
  },
13
13
  "dependencies": {
14
- "@weborigami/async-tree": "0.4.2",
15
- "@weborigami/types": "0.4.2",
14
+ "@weborigami/async-tree": "0.5.0",
15
+ "@weborigami/types": "0.5.0",
16
16
  "watcher": "2.3.1",
17
- "yaml": "2.7.0"
17
+ "yaml": "2.8.1"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "peggy --allowed-start-rules=\"*\" --format es src/compiler/origami.pegjs --output src/compiler/parse.js",
@@ -5,9 +5,8 @@ import { parse } from "./parse.js";
5
5
 
6
6
  function compile(source, options) {
7
7
  const { front, startRule } = options;
8
- const mode = options.mode ?? "shell";
8
+ const mode = options.mode ?? "program";
9
9
  const globals = options.globals ?? jsGlobals;
10
- const enableCaching = options.enableCaching ?? true;
11
10
  if (typeof source === "string") {
12
11
  source = { text: source };
13
12
  }
@@ -17,11 +16,10 @@ function compile(source, options) {
17
16
  mode,
18
17
  startRule,
19
18
  });
20
- const cache = enableCaching ? {} : null;
19
+ const cache = mode === "program" ? {} : null;
21
20
  const optimized = optimize(code, {
22
21
  cache,
23
22
  globals,
24
- mode,
25
23
  });
26
24
  const fn = createExpressionFunction(optimized);
27
25
  return fn;
@@ -154,7 +154,7 @@ function compoundReference(key, globals, locals, location) {
154
154
  // Process the remaining parts as property accesses
155
155
  while (tail.length > 0) {
156
156
  const part = tail.shift();
157
- result = annotate([result, part], location);
157
+ result = annotate([ops.property, result, part], location);
158
158
  }
159
159
 
160
160
  return { type, result };
@@ -297,7 +297,12 @@ function resolvePath(code, globals, locals, cache) {
297
297
  let { type, result } = reference(head, globals, locals);
298
298
 
299
299
  if (tail.length > 0) {
300
- if (result instanceof Array) {
300
+ // If the result is a traversal, we can safely extend it
301
+ const extendResult =
302
+ result instanceof Array &&
303
+ result[0] instanceof Array &&
304
+ (result[0][0] === ops.scope || result[0][0] === ops.context);
305
+ if (extendResult) {
301
306
  result.push(...tail);
302
307
  } else {
303
308
  result = annotate([result, ...tail], code.location);
@@ -205,7 +205,11 @@ doubleQuoteString "double quote string"
205
205
  doubleQuoteStringChar
206
206
  = !('"' / newLine) @textChar
207
207
 
208
- ellipsis = "..." / "…" // Unicode ellipsis
208
+ ellipsis
209
+ = "..."
210
+ / "…" {
211
+ console.warn("The use of the Unicode ellipsis character for an object spread is deprecated; use `...` (three periods) instead.");
212
+ }
209
213
 
210
214
  equalityExpression
211
215
  = head:relationalExpression tail:(__ @equalityOperator __ @relationalExpression)* {
@@ -655,7 +659,7 @@ programMode
655
659
  = &{ return options.mode === "program" }
656
660
 
657
661
  propertyAccess
658
- = __ "." __ property:identifierLiteral {
662
+ = whitespaceOptionalForProgram "." whitespaceOptionalForProgram property:identifierLiteral {
659
663
  return annotate([markers.property, property], location());
660
664
  }
661
665
 
@@ -786,13 +790,7 @@ templateBodyText "template text"
786
790
 
787
791
  templateDocument "template document"
788
792
  = front:frontMatterExpression __ body:templateBody {
789
- // TODO: Deprecate @template
790
- const macroName = text().includes("@template") ? "@template" : "_template";
791
- if (macroName === "@template") {
792
- // If the front matter is a macro, apply it to the body
793
- console.warn("Warning: the @template() macro is deprecated. Use _template() instead.");
794
- }
795
- return annotate(applyMacro(front, macroName, body), location());
793
+ return annotate(applyMacro(front, "_template", body), location());
796
794
  }
797
795
  / front:frontMatterYaml body:templateBody {
798
796
  return makeDocument(front, body, location());
@@ -903,5 +901,11 @@ whitespaceChar
903
901
  // `/s` definition to avoid missing any.
904
902
  = char:. &{ return /\s/.test(char); } { return char; }
905
903
 
904
+ // In some cases whitespace isn't allowed in shell mode but is allowed in
905
+ // program mode
906
+ whitespaceOptionalForProgram
907
+ = programMode __
908
+ / shellMode
909
+
906
910
  whitespaceWithNewLine
907
911
  = inlineSpace* comment? newLine __