plainscript-lang 1.0.2 → 1.0.3

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 (74) hide show
  1. package/README.md +173 -738
  2. package/compiler/bundler.js +83 -12
  3. package/compiler/cli.js +74 -27
  4. package/compiler/dependency-detector.js +11 -0
  5. package/compiler/generator.js +372 -35
  6. package/compiler/lexer.js +2 -0
  7. package/compiler/parser.js +410 -28
  8. package/compiler/sourcemap.js +142 -0
  9. package/compiler/version.js +1 -1
  10. package/docs/CAPABILITY_GAP_AUDIT.md +98 -534
  11. package/docs/PLAINSCRIPT-SPEC.md +304 -551
  12. package/docs/index.html +127 -598
  13. package/docs/website/script.js +185 -1006
  14. package/docs/website/style.css +220 -656
  15. package/examples/ai-providers.pln +7 -0
  16. package/examples/arrays.pln +4 -12
  17. package/examples/async-errors.pln +18 -0
  18. package/examples/auth-api.pln +3 -50
  19. package/examples/auth-sessions.pln +32 -0
  20. package/examples/basics.pln +14 -0
  21. package/examples/bots.pln +13 -0
  22. package/examples/cache-and-jobs.pln +6 -28
  23. package/examples/cache-schedule.pln +22 -0
  24. package/examples/collections.pln +15 -0
  25. package/examples/concurrency.pln +12 -43
  26. package/examples/conditions.pln +22 -0
  27. package/examples/database.pln +6 -39
  28. package/examples/day2.pln +6 -6
  29. package/examples/day3.pln +4 -10
  30. package/examples/deployment.pln +3 -9
  31. package/examples/email-send.pln +3 -22
  32. package/examples/error-handling.pln +6 -54
  33. package/examples/expressions.pln +7 -40
  34. package/examples/file-uploads.pln +5 -34
  35. package/examples/files-and-config.pln +5 -46
  36. package/examples/files.pln +12 -0
  37. package/examples/football-backend/app.pln +21 -20
  38. package/examples/functions.pln +17 -0
  39. package/examples/hello.pln +2 -3
  40. package/examples/http-client.pln +3 -44
  41. package/examples/http.pln +11 -0
  42. package/examples/id-verification/app.pln +4 -3
  43. package/examples/id-verification/make-sample-id.js +29 -42
  44. package/examples/json.pln +11 -0
  45. package/examples/loops.pln +13 -11
  46. package/examples/modules/app.pln +3 -16
  47. package/examples/modules/main.pln +4 -0
  48. package/examples/modules/math.pln +5 -16
  49. package/examples/mongo.pln +33 -0
  50. package/examples/objects.pln +3 -11
  51. package/examples/ocr.pln +22 -0
  52. package/examples/packages.pln +6 -0
  53. package/examples/record-kinds.pln +6 -42
  54. package/examples/records.pln +15 -0
  55. package/examples/rest-api-fetch.pln +6 -90
  56. package/examples/rest-api.pln +5 -65
  57. package/examples/scheduled-tasks.pln +4 -23
  58. package/examples/search-and-filter.pln +4 -34
  59. package/examples/server.pln +5 -24
  60. package/examples/sessions-and-cookies.pln +4 -50
  61. package/examples/sqlite.pln +23 -0
  62. package/examples/start.pln +2 -2
  63. package/examples/stdlib.pln +4 -41
  64. package/examples/string-verbs.pln +16 -0
  65. package/examples/telegram-ai-bot.pln +19 -0
  66. package/examples/telegram-bot.pln +4 -40
  67. package/examples/testing.pln +13 -0
  68. package/examples/web-api.pln +27 -0
  69. package/examples/web-app.pln +4 -16
  70. package/examples/websocket-server.pln +5 -26
  71. package/examples/websocket.pln +13 -0
  72. package/examples/whatsapp-bot/pairing.pln +4 -5
  73. package/examples/whatsapp-bot/qr.pln +7 -3
  74. package/package.json +3 -2
@@ -0,0 +1,142 @@
1
+ // SourceMap: V3 Source Map generator for PlainScript compiler.
2
+ // Zero external dependencies — implements VLQ Base64 encoding.
3
+
4
+ const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
5
+
6
+ function encodeVlq(value) {
7
+ let vlq = value < 0 ? ((-value) << 1) | 1 : (value << 1);
8
+ let encoded = '';
9
+ do {
10
+ let digit = vlq & 31;
11
+ vlq >>>= 5;
12
+ if (vlq > 0) {
13
+ digit |= 32;
14
+ }
15
+ encoded += BASE64_CHARS[digit];
16
+ } while (vlq > 0);
17
+ return encoded;
18
+ }
19
+
20
+ function decodeVlq(str, state = { index: 0 }) {
21
+ let result = 0;
22
+ let shift = 0;
23
+ let continuation = true;
24
+ while (continuation && state.index < str.length) {
25
+ const char = str[state.index++];
26
+ const digit = BASE64_CHARS.indexOf(char);
27
+ if (digit === -1) throw new Error(`Invalid Base64 character: ${char}`);
28
+ continuation = (digit & 32) !== 0;
29
+ result += (digit & 31) << shift;
30
+ shift += 5;
31
+ }
32
+ const isNegative = (result & 1) === 1;
33
+ const value = result >> 1;
34
+ return isNegative ? -value : value;
35
+ }
36
+
37
+ class SourceMapGenerator {
38
+ constructor(options = {}) {
39
+ this.file = options.file || '';
40
+ this.sourceRoot = options.sourceRoot || '';
41
+ this.sources = [];
42
+ this.sourcesContent = [];
43
+ this.mappings = [];
44
+ }
45
+
46
+ addSource(sourcePath, content = null) {
47
+ let idx = this.sources.indexOf(sourcePath);
48
+ if (idx === -1) {
49
+ idx = this.sources.length;
50
+ this.sources.push(sourcePath);
51
+ this.sourcesContent.push(content);
52
+ } else if (content !== null && this.sourcesContent[idx] === null) {
53
+ this.sourcesContent[idx] = content;
54
+ }
55
+ return idx;
56
+ }
57
+
58
+ addMapping({ generated, original, source }) {
59
+ if (!generated || generated.line == null || generated.column == null) return;
60
+ if (!original || original.line == null || original.column == null) return;
61
+
62
+ const sourceIdx = source ? this.addSource(source) : 0;
63
+ this.mappings.push({
64
+ generatedLine: generated.line,
65
+ generatedColumn: generated.column,
66
+ originalLine: original.line,
67
+ originalColumn: original.column,
68
+ sourceIdx,
69
+ });
70
+ }
71
+
72
+ toJSON() {
73
+ // Sort mappings by generated line, then generated column
74
+ const sorted = [...this.mappings].sort((a, b) => {
75
+ if (a.generatedLine !== b.generatedLine) return a.generatedLine - b.generatedLine;
76
+ return a.generatedColumn - b.generatedColumn;
77
+ });
78
+
79
+ let mappingsStr = '';
80
+ let prevGenLine = 1;
81
+ let prevGenCol = 0;
82
+ let prevOrigLine = 0;
83
+ let prevOrigCol = 0;
84
+ let prevSourceIdx = 0;
85
+
86
+ for (const m of sorted) {
87
+ while (prevGenLine < m.generatedLine) {
88
+ mappingsStr += ';';
89
+ prevGenLine++;
90
+ prevGenCol = 0;
91
+ }
92
+
93
+ if (mappingsStr.length > 0 && !mappingsStr.endsWith(';')) {
94
+ mappingsStr += ',';
95
+ }
96
+
97
+ const genColDiff = m.generatedColumn - prevGenCol;
98
+ const sourceIdxDiff = m.sourceIdx - prevSourceIdx;
99
+ const origLineDiff = (m.originalLine - 1) - prevOrigLine;
100
+ const origColDiff = (m.originalColumn - 1) - prevOrigCol;
101
+
102
+ mappingsStr += encodeVlq(genColDiff);
103
+ mappingsStr += encodeVlq(sourceIdxDiff);
104
+ mappingsStr += encodeVlq(origLineDiff);
105
+ mappingsStr += encodeVlq(origColDiff);
106
+
107
+ prevGenCol = m.generatedColumn;
108
+ prevSourceIdx = m.sourceIdx;
109
+ prevOrigLine = m.originalLine - 1;
110
+ prevOrigCol = m.originalColumn - 1;
111
+ }
112
+
113
+ const mapObj = {
114
+ version: 3,
115
+ file: this.file,
116
+ sources: this.sources,
117
+ mappings: mappingsStr,
118
+ };
119
+
120
+ if (this.sourcesContent.some(c => c !== null)) {
121
+ mapObj.sourcesContent = this.sourcesContent;
122
+ }
123
+
124
+ return mapObj;
125
+ }
126
+
127
+ toString() {
128
+ return JSON.stringify(this.toJSON());
129
+ }
130
+
131
+ toInlineDataUrl() {
132
+ const json = this.toString();
133
+ const base64 = Buffer.from(json, 'utf8').toString('base64');
134
+ return `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64}`;
135
+ }
136
+ }
137
+
138
+ module.exports = {
139
+ SourceMapGenerator,
140
+ encodeVlq,
141
+ decodeVlq,
142
+ };
@@ -1,6 +1,6 @@
1
1
  // Single source of truth for the compiler version.
2
2
  // Consumed by cli.js help/version output.
3
3
 
4
- const VERSION = '1.0.2';
4
+ const VERSION = '1.0.3';
5
5
 
6
6
  module.exports = { VERSION };