tjs-lang 0.8.7 → 0.9.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.
Files changed (75) hide show
  1. package/CLAUDE.md +12 -4
  2. package/dist/experiments/ambient/probe.d.ts +52 -0
  3. package/dist/index.js +115 -171
  4. package/dist/index.js.map +4 -4
  5. package/dist/scripts/build-editors.d.ts +19 -0
  6. package/dist/src/css/dimensions.d.ts +23 -0
  7. package/dist/src/css/index.d.ts +85 -0
  8. package/dist/src/css/predicates.d.ts +38 -0
  9. package/dist/src/css/shorthands.d.ts +31 -0
  10. package/dist/src/css/style.d.ts +48 -0
  11. package/dist/src/lang/emitters/js.d.ts +9 -1
  12. package/dist/src/lang/index.d.ts +2 -2
  13. package/dist/src/lang/parser-transforms.d.ts +9 -5
  14. package/dist/src/lang/parser.d.ts +2 -0
  15. package/dist/src/lang/predicate.d.ts +60 -0
  16. package/dist/src/lang/transpiler.d.ts +3 -2
  17. package/dist/src/lang/types.d.ts +16 -0
  18. package/dist/src/schema/index.d.ts +12 -0
  19. package/dist/tjs-browser-from-ts.js +20 -20
  20. package/dist/tjs-browser-from-ts.js.map +3 -3
  21. package/dist/tjs-browser.js +100 -90
  22. package/dist/tjs-browser.js.map +4 -4
  23. package/dist/tjs-css.js +193 -0
  24. package/dist/tjs-css.js.map +7 -0
  25. package/dist/tjs-eval.js +43 -42
  26. package/dist/tjs-eval.js.map +4 -4
  27. package/dist/tjs-from-ts.js +13 -13
  28. package/dist/tjs-from-ts.js.map +2 -2
  29. package/dist/tjs-lang.js +102 -92
  30. package/dist/tjs-lang.js.map +4 -4
  31. package/dist/tjs-runtime.js +10 -0
  32. package/dist/tjs-runtime.js.map +7 -0
  33. package/dist/tjs-schema.js +6 -0
  34. package/dist/tjs-schema.js.map +7 -0
  35. package/dist/tjs-vm.js +55 -54
  36. package/dist/tjs-vm.js.map +4 -4
  37. package/docs/ambient-contracts.md +261 -0
  38. package/editors/ace/ajs-mode.js +214 -233
  39. package/editors/codemirror/ajs-language.js +1570 -233
  40. package/editors/editors-build.test.ts +29 -0
  41. package/editors/monaco/ajs-monarch.js +239 -195
  42. package/llms.txt +4 -0
  43. package/package.json +35 -4
  44. package/src/css/css.test.ts +122 -0
  45. package/src/css/dimensions.test.ts +112 -0
  46. package/src/css/dimensions.ts +146 -0
  47. package/src/css/index.ts +243 -0
  48. package/src/css/perf.bench.test.ts +109 -0
  49. package/src/css/predicates.ts +232 -0
  50. package/src/css/property-aware.test.ts +84 -0
  51. package/src/css/shorthands.test.ts +90 -0
  52. package/src/css/shorthands.ts +113 -0
  53. package/src/css/style.test.ts +125 -0
  54. package/src/css/style.ts +134 -0
  55. package/src/index-tsfree.test.ts +58 -0
  56. package/src/lang/emit-verified-predicate.test.ts +95 -0
  57. package/src/lang/emitters/dts.test.ts +31 -0
  58. package/src/lang/emitters/dts.ts +23 -4
  59. package/src/lang/emitters/js.ts +33 -1
  60. package/src/lang/from-ts.test.ts +1 -1
  61. package/src/lang/generic-verified-predicate.test.ts +39 -0
  62. package/src/lang/index.ts +14 -5
  63. package/src/lang/parser-transforms.ts +109 -14
  64. package/src/lang/parser.ts +9 -2
  65. package/src/lang/predicate-evaluator.test.ts +49 -0
  66. package/src/lang/predicate-report.test.ts +54 -0
  67. package/src/lang/predicate.ts +268 -0
  68. package/src/lang/redos-lint.test.ts +81 -0
  69. package/src/lang/transpiler.ts +13 -0
  70. package/src/lang/type-verified-predicate.test.ts +83 -0
  71. package/src/lang/types.ts +17 -0
  72. package/src/lang/typescript-syntax.test.ts +2 -1
  73. package/src/schema/index.ts +62 -0
  74. package/src/schema/schema.test.ts +66 -0
  75. package/src/use-cases/bootstrap.test.ts +14 -4
@@ -1,328 +1,309 @@
1
- /**
2
- * Ace Editor Mode for AsyncJS
3
- *
4
- * Usage:
5
- * ```html
6
- * <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.2/ace.js"></script>
7
- * <script src="path/to/ajs-mode.js"></script>
8
- * <script>
9
- * const editor = ace.edit("editor");
10
- * editor.session.setMode("ace/mode/ajs");
11
- * </script>
12
- * ```
13
- *
14
- * Or as ES module:
15
- * ```javascript
16
- * import ace from 'ace-builds'
17
- * import { registerAjsMode } from 'tjs-lang/editors/ace/ajs-mode'
18
- * registerAjsMode(ace)
19
- * editor.session.setMode('ace/mode/ajs')
20
- * ```
21
- */
22
-
23
- // Forbidden keywords in AsyncJS - these will be highlighted as errors
24
- const FORBIDDEN_KEYWORDS = [
25
- 'new',
26
- 'class',
27
- 'async',
28
- 'await',
29
- 'var',
30
- 'this',
31
- 'super',
32
- 'extends',
33
- 'implements',
34
- 'interface',
35
- 'type',
36
- 'yield',
37
- 'import',
38
- 'export',
39
- 'require',
40
- 'throw',
41
- ]
42
-
43
- // Valid keywords in AsyncJS
44
- const KEYWORDS = [
45
- 'function',
46
- 'return',
47
- 'if',
48
- 'else',
49
- 'while',
50
- 'for',
51
- 'of',
52
- 'in',
53
- 'try',
54
- 'catch',
55
- 'finally',
56
- 'let',
57
- 'const',
58
- ]
59
-
60
- // Language constants
61
- const CONSTANTS = ['true', 'false', 'null']
62
-
63
- // Built-in type constructors
64
- const BUILTINS = [
65
- 'Date',
66
- 'Set',
67
- 'Map',
68
- 'Array',
69
- 'Object',
70
- 'String',
71
- 'Number',
72
- 'Math',
73
- 'JSON',
74
- ]
75
-
76
- /**
77
- * Create the AsyncJS highlight rules for Ace
78
- */
1
+ // editors/ajs-syntax.ts
2
+ var KEYWORDS = [
3
+ "function",
4
+ "return",
5
+ "if",
6
+ "else",
7
+ "while",
8
+ "for",
9
+ "of",
10
+ "in",
11
+ "try",
12
+ "catch",
13
+ "finally",
14
+ "let",
15
+ "const",
16
+ "true",
17
+ "false",
18
+ "null",
19
+ "undefined"
20
+ ];
21
+ var FORBIDDEN_KEYWORDS = [
22
+ // Object-oriented constructs
23
+ "new",
24
+ "class",
25
+ "extends",
26
+ "super",
27
+ "this",
28
+ "implements",
29
+ "interface",
30
+ "abstract",
31
+ "static",
32
+ "private",
33
+ "protected",
34
+ "public",
35
+ // Async constructs (not needed - runtime handles async)
36
+ "async",
37
+ "await",
38
+ "yield",
39
+ // Module system (not supported)
40
+ "import",
41
+ "export",
42
+ "require",
43
+ "module",
44
+ // Other unsupported
45
+ "var",
46
+ // use let/const
47
+ "throw",
48
+ // use Error() for monadic error flow
49
+ "switch",
50
+ // use if/else chains
51
+ "case",
52
+ "default",
53
+ // (as switch keyword)
54
+ "with",
55
+ "delete",
56
+ "void",
57
+ "typeof",
58
+ // use type-by-example instead
59
+ "instanceof",
60
+ "debugger",
61
+ "eval",
62
+ // TypeScript-specific (not supported)
63
+ "type",
64
+ "enum",
65
+ "namespace",
66
+ "declare",
67
+ "readonly",
68
+ "as",
69
+ "is",
70
+ "keyof",
71
+ "infer",
72
+ "never",
73
+ "unknown"
74
+ ];
75
+ var TYPE_CONSTRUCTORS = [
76
+ "Date",
77
+ "Set",
78
+ "Map",
79
+ "Array",
80
+ "Object",
81
+ "String",
82
+ "Number",
83
+ "Boolean",
84
+ "RegExp",
85
+ "Error",
86
+ "JSON",
87
+ "Math",
88
+ "Schema"
89
+ // AsyncJS-specific
90
+ ];
91
+ var FORBIDDEN_SET = new Set(FORBIDDEN_KEYWORDS);
92
+ var KEYWORDS_SET = new Set(KEYWORDS);
93
+ var FORBIDDEN_PATTERN = new RegExp(
94
+ `\\b(${FORBIDDEN_KEYWORDS.join("|")})\\b`,
95
+ "g"
96
+ );
97
+
98
+ // editors/ace/ajs-mode.ts
99
+ var FORBIDDEN_KEYWORDS2 = [...FORBIDDEN_KEYWORDS];
100
+ var KEYWORDS2 = [...KEYWORDS];
101
+ var CONSTANTS = ["true", "false", "null", "undefined"];
102
+ var BUILTINS = [...TYPE_CONSTRUCTORS];
79
103
  function createAjsHighlightRules(ace) {
80
- const oop = ace.require('ace/lib/oop')
104
+ const oop = ace.require("ace/lib/oop");
81
105
  const TextHighlightRules = ace.require(
82
- 'ace/mode/text_highlight_rules'
83
- ).TextHighlightRules
84
-
106
+ "ace/mode/text_highlight_rules"
107
+ ).TextHighlightRules;
85
108
  function AjsHighlightRules() {
86
109
  const keywordMapper = this.createKeywordMapper(
87
110
  {
88
- 'invalid.illegal': FORBIDDEN_KEYWORDS.join('|'),
89
- keyword: KEYWORDS.join('|'),
90
- 'constant.language': CONSTANTS.join('|'),
91
- 'support.function': BUILTINS.join('|'),
111
+ "invalid.illegal": FORBIDDEN_KEYWORDS2.join("|"),
112
+ keyword: KEYWORDS2.join("|"),
113
+ "constant.language": CONSTANTS.join("|"),
114
+ "support.function": BUILTINS.join("|")
92
115
  },
93
- 'identifier'
94
- )
95
-
116
+ "identifier"
117
+ );
96
118
  this.$rules = {
97
119
  start: [
98
120
  // Comments
99
121
  {
100
- token: 'comment.line',
101
- regex: /\/\/.*$/,
122
+ token: "comment.line",
123
+ regex: /\/\/.*$/
102
124
  },
103
125
  {
104
- token: 'comment.block.documentation',
126
+ token: "comment.block.documentation",
105
127
  regex: /\/\*\*/,
106
- next: 'doc_comment',
128
+ next: "doc_comment"
107
129
  },
108
130
  {
109
- token: 'comment.block',
131
+ token: "comment.block",
110
132
  regex: /\/\*/,
111
- next: 'block_comment',
133
+ next: "block_comment"
112
134
  },
113
-
114
135
  // Strings - must come before keywords to avoid highlighting inside strings
115
136
  {
116
- token: 'string.quoted.single',
117
- regex: /'(?:[^'\\]|\\.)*'/,
137
+ token: "string.quoted.single",
138
+ regex: /'(?:[^'\\]|\\.)*'/
118
139
  },
119
140
  {
120
- token: 'string.quoted.double',
121
- regex: /"(?:[^"\\]|\\.)*"/,
141
+ token: "string.quoted.double",
142
+ regex: /"(?:[^"\\]|\\.)*"/
122
143
  },
123
144
  // Template literals with embedded expressions
124
145
  {
125
- token: 'string.template',
146
+ token: "string.template",
126
147
  regex: /`/,
127
- next: 'template_string',
148
+ next: "template_string"
128
149
  },
129
-
130
150
  // Numbers
131
151
  {
132
- token: 'constant.numeric.float',
133
- regex: /\d+\.\d+(?:[eE][+-]?\d+)?/,
152
+ token: "constant.numeric.float",
153
+ regex: /\d+\.\d+(?:[eE][+-]?\d+)?/
134
154
  },
135
155
  {
136
- token: 'constant.numeric.hex',
137
- regex: /0[xX][0-9a-fA-F]+/,
156
+ token: "constant.numeric.hex",
157
+ regex: /0[xX][0-9a-fA-F]+/
138
158
  },
139
159
  {
140
- token: 'constant.numeric',
141
- regex: /\d+/,
160
+ token: "constant.numeric",
161
+ regex: /\d+/
142
162
  },
143
-
144
163
  // Function definition
145
164
  {
146
- token: ['keyword', 'text', 'entity.name.function'],
147
- regex: /(function)(\s+)([a-zA-Z_$][a-zA-Z0-9_$]*)/,
165
+ token: ["keyword", "text", "entity.name.function"],
166
+ regex: /(function)(\s+)([a-zA-Z_$][a-zA-Z0-9_$]*)/
148
167
  },
149
-
150
168
  // Keywords and identifiers
151
169
  {
152
170
  token: keywordMapper,
153
- regex: /[a-zA-Z_$][a-zA-Z0-9_$]*/,
171
+ regex: /[a-zA-Z_$][a-zA-Z0-9_$]*/
154
172
  },
155
-
156
173
  // Operators
157
174
  {
158
- token: 'keyword.operator',
159
- regex: /\+\+|--|\*\*|&&|\|\||==|!=|>=|<=|=>|[+\-*/%=<>!&|^~?:]/,
175
+ token: "keyword.operator",
176
+ regex: /\+\+|--|\*\*|&&|\|\||==|!=|>=|<=|=>|[+\-*/%=<>!&|^~?:]/
160
177
  },
161
-
162
178
  // Brackets
163
179
  {
164
- token: 'paren.lparen',
165
- regex: /[{(\[]/,
180
+ token: "paren.lparen",
181
+ regex: /[{(\[]/
166
182
  },
167
183
  {
168
- token: 'paren.rparen',
169
- regex: /[})\]]/,
184
+ token: "paren.rparen",
185
+ regex: /[})\]]/
170
186
  },
171
-
172
187
  // Punctuation
173
188
  {
174
- token: 'punctuation',
175
- regex: /[;,.:]/,
176
- },
189
+ token: "punctuation",
190
+ regex: /[;,.:]/
191
+ }
177
192
  ],
178
-
179
193
  block_comment: [
180
194
  {
181
- token: 'comment.block',
195
+ token: "comment.block",
182
196
  regex: /\*\//,
183
- next: 'start',
197
+ next: "start"
184
198
  },
185
199
  {
186
- defaultToken: 'comment.block',
187
- },
200
+ defaultToken: "comment.block"
201
+ }
188
202
  ],
189
-
190
203
  doc_comment: [
191
204
  {
192
- token: 'comment.block.documentation',
205
+ token: "comment.block.documentation",
193
206
  regex: /\*\//,
194
- next: 'start',
207
+ next: "start"
195
208
  },
196
209
  {
197
- token: 'keyword.other.documentation',
198
- regex: /@(?:param|returns?|description|example)\b/,
210
+ token: "keyword.other.documentation",
211
+ regex: /@(?:param|returns?|description|example)\b/
199
212
  },
200
213
  {
201
- defaultToken: 'comment.block.documentation',
202
- },
214
+ defaultToken: "comment.block.documentation"
215
+ }
203
216
  ],
204
-
205
217
  template_string: [
206
218
  {
207
- token: 'string.template',
219
+ token: "string.template",
208
220
  regex: /`/,
209
- next: 'start',
221
+ next: "start"
210
222
  },
211
223
  {
212
- token: 'constant.character.escape',
213
- regex: /\\./,
224
+ token: "constant.character.escape",
225
+ regex: /\\./
214
226
  },
215
227
  {
216
- token: 'paren.quasi.start',
228
+ token: "paren.quasi.start",
217
229
  regex: /\$\{/,
218
- push: 'template_expression',
230
+ push: "template_expression"
219
231
  },
220
232
  {
221
- defaultToken: 'string.template',
222
- },
233
+ defaultToken: "string.template"
234
+ }
223
235
  ],
224
-
225
236
  template_expression: [
226
237
  {
227
- token: 'paren.quasi.end',
238
+ token: "paren.quasi.end",
228
239
  regex: /\}/,
229
- next: 'pop',
240
+ next: "pop"
230
241
  },
231
242
  {
232
- include: 'start',
233
- },
234
- ],
235
- }
236
-
237
- this.normalizeRules()
243
+ include: "start"
244
+ }
245
+ ]
246
+ };
247
+ this.normalizeRules();
238
248
  }
239
-
240
- oop.inherits(AjsHighlightRules, TextHighlightRules)
241
-
242
- return AjsHighlightRules
249
+ oop.inherits(AjsHighlightRules, TextHighlightRules);
250
+ return AjsHighlightRules;
243
251
  }
244
-
245
- /**
246
- * Create the AsyncJS mode for Ace
247
- */
248
252
  function createAjsMode(ace) {
249
- const oop = ace.require('ace/lib/oop')
250
- const TextMode = ace.require('ace/mode/text').Mode
253
+ const oop = ace.require("ace/lib/oop");
254
+ const TextMode = ace.require("ace/mode/text").Mode;
251
255
  const MatchingBraceOutdent = ace.require(
252
- 'ace/mode/matching_brace_outdent'
253
- ).MatchingBraceOutdent
256
+ "ace/mode/matching_brace_outdent"
257
+ ).MatchingBraceOutdent;
254
258
  const CstyleBehaviour = ace.require(
255
- 'ace/mode/behaviour/cstyle'
256
- ).CstyleBehaviour
257
- const CStyleFoldMode = ace.require('ace/mode/folding/cstyle').FoldMode
258
-
259
- const AjsHighlightRules = createAjsHighlightRules(ace)
260
-
259
+ "ace/mode/behaviour/cstyle"
260
+ ).CstyleBehaviour;
261
+ const CStyleFoldMode = ace.require("ace/mode/folding/cstyle").FoldMode;
262
+ const AjsHighlightRules = createAjsHighlightRules(ace);
261
263
  function AjsMode() {
262
- this.HighlightRules = AjsHighlightRules
263
- this.$outdent = new MatchingBraceOutdent()
264
- this.$behaviour = new CstyleBehaviour()
265
- this.foldingRules = new CStyleFoldMode()
264
+ this.HighlightRules = AjsHighlightRules;
265
+ this.$outdent = new MatchingBraceOutdent();
266
+ this.$behaviour = new CstyleBehaviour();
267
+ this.foldingRules = new CStyleFoldMode();
266
268
  }
267
-
268
- oop.inherits(AjsMode, TextMode)
269
- ;(function () {
270
- this.lineCommentStart = '//'
271
- this.blockComment = { start: '/*', end: '*/' }
272
-
273
- this.getNextLineIndent = function (state, line, tab) {
274
- let indent = this.$getIndent(line)
275
- if (state === 'start') {
276
- const match = line.match(/^.*[{(\[]\s*$/)
269
+ oop.inherits(AjsMode, TextMode);
270
+ (function() {
271
+ this.lineCommentStart = "//";
272
+ this.blockComment = { start: "/*", end: "*/" };
273
+ this.getNextLineIndent = function(state, line, tab) {
274
+ let indent = this.$getIndent(line);
275
+ if (state === "start") {
276
+ const match = line.match(/^.*[{(\[]\s*$/);
277
277
  if (match) {
278
- indent += tab
278
+ indent += tab;
279
279
  }
280
280
  }
281
- return indent
282
- }
283
-
284
- this.checkOutdent = function (state, line, input) {
285
- return this.$outdent.checkOutdent(line, input)
286
- }
287
-
288
- this.autoOutdent = function (state, doc, row) {
289
- this.$outdent.autoOutdent(doc, row)
290
- }
291
-
292
- this.$id = 'ace/mode/ajs'
293
- }).call(AjsMode.prototype)
294
-
295
- return AjsMode
281
+ return indent;
282
+ };
283
+ this.checkOutdent = function(state, line, input) {
284
+ return this.$outdent.checkOutdent(line, input);
285
+ };
286
+ this.autoOutdent = function(state, doc, row) {
287
+ this.$outdent.autoOutdent(doc, row);
288
+ };
289
+ this.$id = "ace/mode/ajs";
290
+ }).call(AjsMode.prototype);
291
+ return AjsMode;
296
292
  }
297
-
298
- /**
299
- * Register AsyncJS mode with Ace editor
300
- *
301
- * @param {object} ace - The Ace editor instance
302
- */
303
- export function registerAjsMode(ace) {
304
- const AjsMode = createAjsMode(ace)
293
+ function registerAjsMode(ace) {
294
+ const AjsMode = createAjsMode(ace);
305
295
  ace.define(
306
- 'ace/mode/ajs',
307
- ['require', 'exports', 'module'],
308
- function (require, exports) {
309
- exports.Mode = AjsMode
296
+ "ace/mode/ajs",
297
+ ["require", "exports", "module"],
298
+ function(_require, exports) {
299
+ exports.Mode = AjsMode;
310
300
  }
311
- )
312
- }
313
-
314
- // Auto-register if Ace is available globally
315
- if (typeof window !== 'undefined' && window.ace) {
316
- registerAjsMode(window.ace)
317
- }
318
-
319
- // Export for CommonJS/AMD
320
- if (typeof module !== 'undefined' && module.exports) {
321
- module.exports = {
322
- registerAjsMode,
323
- FORBIDDEN_KEYWORDS,
324
- KEYWORDS,
325
- CONSTANTS,
326
- BUILTINS,
327
- }
301
+ );
328
302
  }
303
+ export {
304
+ BUILTINS,
305
+ CONSTANTS,
306
+ FORBIDDEN_KEYWORDS2 as FORBIDDEN_KEYWORDS,
307
+ KEYWORDS2 as KEYWORDS,
308
+ registerAjsMode
309
+ };