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.
- package/README.md +173 -738
- package/compiler/bundler.js +83 -12
- package/compiler/cli.js +74 -27
- package/compiler/dependency-detector.js +11 -0
- package/compiler/generator.js +372 -35
- package/compiler/lexer.js +2 -0
- package/compiler/parser.js +410 -28
- package/compiler/sourcemap.js +142 -0
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +98 -534
- package/docs/PLAINSCRIPT-SPEC.md +304 -551
- package/docs/index.html +127 -598
- package/docs/website/script.js +185 -1006
- package/docs/website/style.css +220 -656
- package/examples/ai-providers.pln +7 -0
- package/examples/arrays.pln +4 -12
- package/examples/async-errors.pln +18 -0
- package/examples/auth-api.pln +3 -50
- package/examples/auth-sessions.pln +32 -0
- package/examples/basics.pln +14 -0
- package/examples/bots.pln +13 -0
- package/examples/cache-and-jobs.pln +6 -28
- package/examples/cache-schedule.pln +22 -0
- package/examples/collections.pln +15 -0
- package/examples/concurrency.pln +12 -43
- package/examples/conditions.pln +22 -0
- package/examples/database.pln +6 -39
- package/examples/day2.pln +6 -6
- package/examples/day3.pln +4 -10
- package/examples/deployment.pln +3 -9
- package/examples/email-send.pln +3 -22
- package/examples/error-handling.pln +6 -54
- package/examples/expressions.pln +7 -40
- package/examples/file-uploads.pln +5 -34
- package/examples/files-and-config.pln +5 -46
- package/examples/files.pln +12 -0
- package/examples/football-backend/app.pln +21 -20
- package/examples/functions.pln +17 -0
- package/examples/hello.pln +2 -3
- package/examples/http-client.pln +3 -44
- package/examples/http.pln +11 -0
- package/examples/id-verification/app.pln +4 -3
- package/examples/id-verification/make-sample-id.js +29 -42
- package/examples/json.pln +11 -0
- package/examples/loops.pln +13 -11
- package/examples/modules/app.pln +3 -16
- package/examples/modules/main.pln +4 -0
- package/examples/modules/math.pln +5 -16
- package/examples/mongo.pln +33 -0
- package/examples/objects.pln +3 -11
- package/examples/ocr.pln +22 -0
- package/examples/packages.pln +6 -0
- package/examples/record-kinds.pln +6 -42
- package/examples/records.pln +15 -0
- package/examples/rest-api-fetch.pln +6 -90
- package/examples/rest-api.pln +5 -65
- package/examples/scheduled-tasks.pln +4 -23
- package/examples/search-and-filter.pln +4 -34
- package/examples/server.pln +5 -24
- package/examples/sessions-and-cookies.pln +4 -50
- package/examples/sqlite.pln +23 -0
- package/examples/start.pln +2 -2
- package/examples/stdlib.pln +4 -41
- package/examples/string-verbs.pln +16 -0
- package/examples/telegram-ai-bot.pln +19 -0
- package/examples/telegram-bot.pln +4 -40
- package/examples/testing.pln +13 -0
- package/examples/web-api.pln +27 -0
- package/examples/web-app.pln +4 -16
- package/examples/websocket-server.pln +5 -26
- package/examples/websocket.pln +13 -0
- package/examples/whatsapp-bot/pairing.pln +4 -5
- package/examples/whatsapp-bot/qr.pln +7 -3
- 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
|
+
};
|