@slim-lang/core 1.2.12 → 1.2.13
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
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ANY, named, literal, arrayOf, tupleOf, genericOf, enumMember, unionOf, intersectionOf, nullable, functionOf
|
|
3
|
+
} from "../external/typeSyntax.js"
|
|
4
|
+
|
|
5
|
+
const KEYWORDS = {
|
|
6
|
+
TSAnyKeyword: "any",
|
|
7
|
+
TSUnknownKeyword: "any",
|
|
8
|
+
TSStringKeyword: "string",
|
|
9
|
+
TSNumberKeyword: "number",
|
|
10
|
+
TSBooleanKeyword: "bool",
|
|
11
|
+
TSNullKeyword: "null",
|
|
12
|
+
TSUndefinedKeyword: "undefined",
|
|
13
|
+
TSVoidKeyword: "undefined",
|
|
14
|
+
TSObjectKeyword: "object",
|
|
15
|
+
TSBigIntKeyword: "bigint",
|
|
16
|
+
TSSymbolKeyword: "symbol"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const UNSUPPORTED = {
|
|
20
|
+
TSTypeLiteral: "object type literals are not supported, declare a struct instead",
|
|
21
|
+
TSMappedType: "mapped types are not supported",
|
|
22
|
+
TSConditionalType: "conditional types are not supported",
|
|
23
|
+
TSIndexedAccessType: "indexed access types are not supported",
|
|
24
|
+
TSTypeQuery: "\"typeof\" in a type position is not supported, use \"type Name = typeof value\"",
|
|
25
|
+
TSInferType: "\"infer\" is not supported",
|
|
26
|
+
TSTemplateLiteralType: "template literal types are not supported",
|
|
27
|
+
TSThisType: "\"this\" type is not supported",
|
|
28
|
+
TSNeverKeyword: "\"never\" type is not supported",
|
|
29
|
+
TSImportType: "import types are not supported, use \"use\" to bring the type in"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function entityName(node) {
|
|
33
|
+
if (node.type === "Identifier") return node.name
|
|
34
|
+
if (node.type === "TSQualifiedName") return `${entityName(node.left)}.${node.right.name}`
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function literalType(node, fail) {
|
|
39
|
+
const value = node.literal
|
|
40
|
+
switch (value.type) {
|
|
41
|
+
case "StringLiteral":
|
|
42
|
+
case "NumericLiteral":
|
|
43
|
+
case "BooleanLiteral":
|
|
44
|
+
return literal(value.value)
|
|
45
|
+
case "UnaryExpression":
|
|
46
|
+
if (value.operator === "-" && value.argument.type === "NumericLiteral") return literal(-value.argument.value)
|
|
47
|
+
break
|
|
48
|
+
case "TemplateLiteral":
|
|
49
|
+
if (value.expressions.length === 0) return literal(value.quasis[0].value.cooked)
|
|
50
|
+
break
|
|
51
|
+
}
|
|
52
|
+
return fail(node, "this literal type is not supported")
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function typeFromAST(node, fail) {
|
|
56
|
+
const convert = child => typeFromAST(child, fail)
|
|
57
|
+
|
|
58
|
+
if (node.type === "TSTypeAnnotation") return convert(node.typeAnnotation)
|
|
59
|
+
if (node.type in KEYWORDS) return named(KEYWORDS[node.type])
|
|
60
|
+
if (node.type in UNSUPPORTED) return fail(node, UNSUPPORTED[node.type])
|
|
61
|
+
|
|
62
|
+
switch (node.type) {
|
|
63
|
+
case "TSTypeReference": {
|
|
64
|
+
const name = entityName(node.typeName)
|
|
65
|
+
const args = (node.typeParameters ?? node.typeArguments)?.params
|
|
66
|
+
return args ? genericOf(name, args.map(convert)) : named(name)
|
|
67
|
+
}
|
|
68
|
+
case "TSArrayType": return arrayOf(convert(node.elementType))
|
|
69
|
+
case "TSTupleType":
|
|
70
|
+
return tupleOf(node.elementTypes.map(element => {
|
|
71
|
+
if (element.type === "TSNamedTupleMember") {
|
|
72
|
+
if (element.optional) fail(element, "optional tuple members are not supported")
|
|
73
|
+
return convert(element.elementType)
|
|
74
|
+
}
|
|
75
|
+
if (element.type === "TSOptionalType" || element.type === "TSRestType") {
|
|
76
|
+
return fail(element, "optional and rest tuple members are not supported")
|
|
77
|
+
}
|
|
78
|
+
return convert(element)
|
|
79
|
+
}))
|
|
80
|
+
case "TSUnionType": return unionOf(node.types.map(convert))
|
|
81
|
+
case "TSIntersectionType": return intersectionOf(node.types.map(convert))
|
|
82
|
+
case "TSParenthesizedType": return convert(node.typeAnnotation)
|
|
83
|
+
case "TSLiteralType": return literalType(node, fail)
|
|
84
|
+
case "TSFunctionType": {
|
|
85
|
+
const params = (node.parameters ?? node.params).map(param => {
|
|
86
|
+
if (param.type === "RestElement") return fail(param, "rest parameters in function types are not supported")
|
|
87
|
+
const annotation = param.typeAnnotation
|
|
88
|
+
return { name: param.type === "Identifier" ? param.name : null, type: annotation ? convert(annotation) : ANY }
|
|
89
|
+
})
|
|
90
|
+
const returns = node.typeAnnotation ?? node.returnType
|
|
91
|
+
return functionOf(params, returns ? convert(returns) : ANY)
|
|
92
|
+
}
|
|
93
|
+
case "TSConstructorType":
|
|
94
|
+
return named("function")
|
|
95
|
+
case "TSTypeOperator":
|
|
96
|
+
if (node.operator === "readonly") return convert(node.typeAnnotation)
|
|
97
|
+
return fail(node, `"${node.operator}" types are not supported`)
|
|
98
|
+
case "TSTypePredicate":
|
|
99
|
+
return named("bool")
|
|
100
|
+
case "SlimNullableType": return nullable(convert(node.typeAnnotation))
|
|
101
|
+
case "SlimEnumMemberType": return enumMember(entityName(node.enumName.typeName), node.member.name)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fail(node, `this type is not supported in Slim`)
|
|
105
|
+
return ANY
|
|
106
|
+
}
|
package/src/test-runner.js
CHANGED
|
@@ -3,10 +3,10 @@ import path from "node:path"
|
|
|
3
3
|
import { spawnSync } from "node:child_process"
|
|
4
4
|
import { pathToFileURL } from "node:url"
|
|
5
5
|
import { transform } from "./transform.js"
|
|
6
|
-
import { distDirName } from "./modulePaths.js"
|
|
6
|
+
import { distDirName, PACKAGE_ROOT } from "./modulePaths.js"
|
|
7
7
|
|
|
8
8
|
const root = process.cwd()
|
|
9
|
-
const runtimeImport = pathToFileURL(path.
|
|
9
|
+
const runtimeImport = pathToFileURL(path.join(PACKAGE_ROOT, "src/external/defaults.js")).href
|
|
10
10
|
const outDir = path.resolve(distDirName(), "__slim_tests__")
|
|
11
11
|
|
|
12
12
|
function findTests(target) {
|
|
@@ -44,12 +44,12 @@ export function runTests(target) {
|
|
|
44
44
|
let failed = 0
|
|
45
45
|
|
|
46
46
|
for (const file of files) {
|
|
47
|
-
const
|
|
47
|
+
const outFile = path.join(outDir, path.basename(file).replace(/\.slim$/, ".mjs"))
|
|
48
|
+
const { code } = transform(fs.readFileSync(file, "utf8"), file, { outFile })
|
|
48
49
|
const executable = code.replace(
|
|
49
|
-
/^import\s+[^;]*defaults\.js";$/m,
|
|
50
|
+
/^import\s+[^;]*(?:defaults|core)\.js";$/m,
|
|
50
51
|
`import ${JSON.stringify(runtimeImport)};`
|
|
51
52
|
)
|
|
52
|
-
const outFile = path.join(outDir, path.basename(file).replace(/\.slim$/, ".mjs"))
|
|
53
53
|
fs.writeFileSync(outFile, executable)
|
|
54
54
|
|
|
55
55
|
console.log(`\n${path.relative(root, file)}`)
|