@slim-lang/core 1.2.12 → 1.2.15
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 +522 -14
- package/package.json +2 -6
- package/packages/slim/server/main.slim +433 -422
- package/run-dev-slim.js +10 -5
- package/run-slim.js +10 -20
- package/src/bin/api/github_get.js +7 -12
- package/src/bin/api/github_req.js +54 -241
- package/src/bin/api/lock.js +2 -1
- package/src/bin/api/spm.js +20 -91
- package/src/bin/cli.js +73 -102
- package/src/bin/config.default.json +11 -11
- package/src/bin/helpers.js +2 -7
- package/src/bin/spm.js +3 -7
- package/src/checker.js +1705 -388
- package/src/compile.js +131 -100
- package/src/external/classErrors.js +5 -6
- package/src/external/client.js +0 -2
- package/src/external/core.js +355 -237
- package/src/external/defaults.js +12 -4
- package/src/external/dom.js +663 -0
- package/src/external/helpers.js +87 -58
- package/src/external/reactive.js +601 -0
- package/src/external/router.js +117 -0
- package/src/external/slim-globals.d.ts +43 -4
- package/src/external/typeSyntax.js +258 -0
- package/src/external/types.js +1 -1
- package/src/format.js +183 -12
- package/src/handlers/errorHandler.js +9 -36
- package/src/jsdoc.js +36 -16
- package/src/modulePaths.js +15 -5
- package/src/reactivity.js +774 -0
- package/src/repl.js +1 -1
- package/src/suggest.js +60 -0
- package/src/syntax/babel.js +46 -0
- package/src/syntax/index.js +39 -0
- package/src/syntax/lower.js +666 -0
- package/src/syntax/markup.js +195 -0
- package/src/syntax/plugin.js +903 -0
- package/src/syntax/types.js +106 -0
- package/src/test-runner.js +5 -5
- package/src/transform.js +209 -244
- package/packages/slim/helpers/string.js +0 -43
- package/packages/slim/types/hash.js +0 -11
- package/src/handlers/parser/components.js +0 -316
- package/src/handlers/parserHandler.js +0 -789
- package/src/lexer.js +0 -174
- package/src/parser.js +0 -803
- package/src/sourcemap.js +0 -0
package/src/lexer.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
const KEYWORDS = new Set([
|
|
2
|
-
"struct", "enum", "type", "func", "component", "use", "lock", "mode", "elif",
|
|
3
|
-
"and", "or", "sizeof", "kindof", "empty", "copyof",
|
|
4
|
-
"break", "case", "catch", "class", "const", "continue", "debugger", "default",
|
|
5
|
-
"delete", "do", "else", "export", "extends", "finally", "for", "function",
|
|
6
|
-
"if", "import", "in", "instanceof", "new", "return", "super", "switch", "this",
|
|
7
|
-
"throw", "try", "typeof", "var", "void", "while", "with", "yield", "let",
|
|
8
|
-
"static", "async", "await", "of", "as", "from"
|
|
9
|
-
])
|
|
10
|
-
|
|
11
|
-
const REGEX_KEYWORDS = new Set([
|
|
12
|
-
"return", "typeof", "instanceof", "in", "of", "new", "delete", "void",
|
|
13
|
-
"do", "else", "yield", "await", "case", "throw"
|
|
14
|
-
])
|
|
15
|
-
|
|
16
|
-
const PUNCTUATORS = [
|
|
17
|
-
">>>=", "===", "!==", ">>>", "**=", "<<=", ">>=", "&&=", "||=", "??=", "...",
|
|
18
|
-
"~/", "::", "=>", "==", "!=", "<=", ">=", "&&", "||", "??", "?.", "**", "++",
|
|
19
|
-
"--", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<", ">>",
|
|
20
|
-
"{", "}", "(", ")", "[", "]", ";", ",", "<", ">", "+", "-", "*", "/", "%",
|
|
21
|
-
"&", "|", "^", "!", "~", "?", ":", "=", ".", "@"
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
const NUMBER = /(?:0[xX][0-9a-fA-F_]+|0[oO][0-7_]+|0[bB][01_]+|(?:\d[\d_]*)?\.?\d[\d_]*(?:[eE][+-]?\d+)?)n?/y
|
|
25
|
-
const NAME = /[A-Za-z_$][\w$]*/y
|
|
26
|
-
|
|
27
|
-
function regexAllowed(prev) {
|
|
28
|
-
if (!prev) return true
|
|
29
|
-
if (prev.type === "number" || prev.type === "string" || prev.type === "regex" || prev.type === "template") {
|
|
30
|
-
return false
|
|
31
|
-
}
|
|
32
|
-
if (prev.type === "name") {
|
|
33
|
-
return prev.keyword && REGEX_KEYWORDS.has(prev.value)
|
|
34
|
-
}
|
|
35
|
-
if (prev.type === "punct") {
|
|
36
|
-
return prev.value !== ")" && prev.value !== "]"
|
|
37
|
-
}
|
|
38
|
-
return true
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function scanRegex(code, start) {
|
|
42
|
-
let i = start + 1
|
|
43
|
-
let inClass = false
|
|
44
|
-
|
|
45
|
-
while (i < code.length) {
|
|
46
|
-
const c = code[i]
|
|
47
|
-
if (c === "\n") return start
|
|
48
|
-
if (c === "\\") { i += 2; continue }
|
|
49
|
-
if (c === "[") inClass = true
|
|
50
|
-
else if (c === "]") inClass = false
|
|
51
|
-
else if (c === "/" && !inClass) { i++; break }
|
|
52
|
-
i++
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (i > code.length) return start
|
|
56
|
-
while (i < code.length && /[a-z]/i.test(code[i])) i++
|
|
57
|
-
return i
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function tokenize(code) {
|
|
61
|
-
const tokens = []
|
|
62
|
-
const modes = [{ kind: "code", brace: 0, interp: false }]
|
|
63
|
-
let prev = null
|
|
64
|
-
let i = 0
|
|
65
|
-
|
|
66
|
-
const emit = (type, start, end, keyword = false) => {
|
|
67
|
-
const token = { type, value: code.slice(start, end), start, end }
|
|
68
|
-
if (keyword) token.keyword = true
|
|
69
|
-
tokens.push(token)
|
|
70
|
-
if (type !== "ws" && type !== "newline" && type !== "comment") prev = token
|
|
71
|
-
return token
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
while (i < code.length) {
|
|
75
|
-
const mode = modes[modes.length - 1]
|
|
76
|
-
|
|
77
|
-
if (mode.kind === "template") {
|
|
78
|
-
const start = i
|
|
79
|
-
while (i < code.length) {
|
|
80
|
-
const c = code[i]
|
|
81
|
-
if (c === "\\") { i += 2; continue }
|
|
82
|
-
if (c === "`" || (c === "$" && code[i + 1] === "{")) break
|
|
83
|
-
i++
|
|
84
|
-
}
|
|
85
|
-
if (i > start) emit("template", start, i)
|
|
86
|
-
|
|
87
|
-
if (code[i] === "`") {
|
|
88
|
-
emit("punct", i, i + 1); i++
|
|
89
|
-
modes.pop()
|
|
90
|
-
} else if (code[i] === "$") {
|
|
91
|
-
emit("punct", i, i + 2); i += 2
|
|
92
|
-
modes.push({ kind: "code", brace: 0, interp: true })
|
|
93
|
-
}
|
|
94
|
-
continue
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const c = code[i]
|
|
98
|
-
|
|
99
|
-
if (c === " " || c === "\t" || c === "\r") {
|
|
100
|
-
const start = i
|
|
101
|
-
while (i < code.length && (code[i] === " " || code[i] === "\t" || code[i] === "\r")) i++
|
|
102
|
-
emit("ws", start, i); continue
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (c === "\n") { emit("newline", i, i + 1); i++; continue }
|
|
106
|
-
|
|
107
|
-
if (c === "/" && code[i + 1] === "/") {
|
|
108
|
-
const start = i
|
|
109
|
-
while (i < code.length && code[i] !== "\n") i++
|
|
110
|
-
emit("comment", start, i); continue
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (c === "/" && code[i + 1] === "*") {
|
|
114
|
-
const start = i
|
|
115
|
-
i += 2
|
|
116
|
-
while (i < code.length && !(code[i] === "*" && code[i + 1] === "/")) i++
|
|
117
|
-
i = Math.min(i + 2, code.length)
|
|
118
|
-
emit("comment", start, i); continue
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (c === "'" || c === '"') {
|
|
122
|
-
const start = i
|
|
123
|
-
i++
|
|
124
|
-
while (i < code.length) {
|
|
125
|
-
if (code[i] === "\\") { i += 2; continue }
|
|
126
|
-
if (code[i] === c || code[i] === "\n") { break }
|
|
127
|
-
i++
|
|
128
|
-
}
|
|
129
|
-
if (code[i] === c) i++
|
|
130
|
-
emit("string", start, i); continue
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (c === "`") {
|
|
134
|
-
emit("punct", i, i + 1); i++
|
|
135
|
-
modes.push({ kind: "template" }); continue
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (c === "}" && mode.interp && mode.brace === 0) {
|
|
139
|
-
emit("punct", i, i + 1); i++
|
|
140
|
-
modes.pop(); continue
|
|
141
|
-
}
|
|
142
|
-
if (c === "{" && mode.interp) mode.brace++
|
|
143
|
-
if (c === "}" && mode.interp) mode.brace--
|
|
144
|
-
|
|
145
|
-
if (c === "/" && regexAllowed(prev)) {
|
|
146
|
-
const end = scanRegex(code, i)
|
|
147
|
-
if (end > i) { emit("regex", i, end); i = end; continue }
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
NUMBER.lastIndex = i
|
|
151
|
-
const num = NUMBER.exec(code)
|
|
152
|
-
if (num && num.index === i && num[0].length > 0) {
|
|
153
|
-
emit("number", i, i + num[0].length); i += num[0].length; continue
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
NAME.lastIndex = i
|
|
157
|
-
const name = NAME.exec(code)
|
|
158
|
-
if (name && name.index === i) {
|
|
159
|
-
emit("name", i, i + name[0].length, KEYWORDS.has(name[0])); i += name[0].length; continue
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
let matched = null
|
|
163
|
-
for (const p of PUNCTUATORS) {
|
|
164
|
-
if (code.startsWith(p, i)) { matched = p; break }
|
|
165
|
-
}
|
|
166
|
-
if (matched) {
|
|
167
|
-
emit("punct", i, i + matched.length); i += matched.length; continue
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
emit("other", i, i + 1); i++
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return tokens
|
|
174
|
-
}
|