@slim-lang/core 1.2.10 → 1.2.12
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/package.json +1 -1
- package/run-dev-slim.js +2 -1
- package/run-slim.js +2 -1
- package/src/bin/cli.js +1 -1
- package/src/bin/config.default.json +11 -7
- package/src/compile.js +6 -3
- package/src/handlers/parser/components.js +23 -2
- package/src/modulePaths.js +9 -4
package/package.json
CHANGED
package/run-dev-slim.js
CHANGED
|
@@ -12,7 +12,8 @@ const config = JSON.parse(
|
|
|
12
12
|
fs.readFileSync("slimconfig.json", "utf8")
|
|
13
13
|
);
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const distName = (config.names && config.names.dist) ?? config.dist;
|
|
16
|
+
const distDir = typeof distName === "string" && distName.trim() ? distName : "slim-dist";
|
|
16
17
|
const entry = `${distDir}/${config.main}.js`;
|
|
17
18
|
const hot = process.argv.includes("--hot");
|
|
18
19
|
|
package/run-slim.js
CHANGED
|
@@ -11,7 +11,8 @@ const root = process.cwd();
|
|
|
11
11
|
|
|
12
12
|
const config = JSON.parse(readFileSync(path.join(root, 'slimconfig.json'), 'utf8'));
|
|
13
13
|
const mainFile = config.main;
|
|
14
|
-
const
|
|
14
|
+
const distName = (config.names && config.names.dist) ?? config.dist;
|
|
15
|
+
const distDir = typeof distName === 'string' && distName.trim() ? distName : 'slim-dist';
|
|
15
16
|
|
|
16
17
|
const dist = path.join(root, distDir, `${mainFile}.js`);
|
|
17
18
|
const args = ['--enable-source-maps', '--no-warnings', dist];
|
package/src/bin/cli.js
CHANGED
|
@@ -351,7 +351,7 @@ program
|
|
|
351
351
|
packageCheck()
|
|
352
352
|
|
|
353
353
|
if (!fs.existsSync(slimConfigPath)) {
|
|
354
|
-
fs.writeFileSync(slimConfigPath, JSON.stringify({ main: "index",
|
|
354
|
+
fs.writeFileSync(slimConfigPath, JSON.stringify({ main: "index", uses: { style: "import", enabled: true } }, null, 4), "utf8")
|
|
355
355
|
log("Created slimconfig.json")
|
|
356
356
|
} else {
|
|
357
357
|
log("slimconfig.json already exists, leaving it untouched")
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
"main": "path/to/your/files",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
{
|
|
2
|
+
"main": "path/to/your/files",
|
|
3
|
+
"uses": {
|
|
4
|
+
"style": "import",
|
|
5
|
+
"enabled": true
|
|
6
|
+
},
|
|
7
|
+
"names": {
|
|
8
|
+
"packages": "packages",
|
|
9
|
+
"dist": "slim-dist"
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/compile.js
CHANGED
|
@@ -90,7 +90,7 @@ function compileFile(slimFile, isEntry = false, mainEntry = null) {
|
|
|
90
90
|
|
|
91
91
|
if (!usePackages && uses.length > 0) {
|
|
92
92
|
const err = new UseError(
|
|
93
|
-
`The "use" feature is disabled. Set "
|
|
93
|
+
`The "use" feature is disabled. Set "uses": { "enabled": true } in slimconfig.json to enable imports (in ${abs}, found: use ${uses[0]})`
|
|
94
94
|
)
|
|
95
95
|
console.error(err)
|
|
96
96
|
process.exit(1)
|
|
@@ -209,11 +209,14 @@ async function main() {
|
|
|
209
209
|
process.exit(1)
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
|
|
212
|
+
const uses = data.uses && typeof data.uses === "object" ? data.uses : null
|
|
213
|
+
usePackages = uses ? uses.enabled !== false : data.usePackages !== false
|
|
214
|
+
useStyle = uses
|
|
215
|
+
? (typeof uses.style === "string" ? uses.style : "import")
|
|
216
|
+
: (typeof data.uses === "string" ? data.uses : "import")
|
|
213
217
|
jsdoc = data.jsdoc === true
|
|
214
218
|
declarations = data.declarations === true
|
|
215
219
|
check = data.check !== false && process.env.SLIM_NO_CHECK !== "1"
|
|
216
|
-
useStyle = typeof data.uses === "string" ? data.uses : "import"
|
|
217
220
|
|
|
218
221
|
if (!("main" in data)) return
|
|
219
222
|
|
|
@@ -22,8 +22,6 @@ function kebabCase(name) {
|
|
|
22
22
|
.toLowerCase()
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// The expression that turns the template into a DOM element, resolving `&`
|
|
26
|
-
// parent references first when BEM classes are enabled.
|
|
27
25
|
function elementExpr(html, name) {
|
|
28
26
|
if (!useBEMClasses()) return `htmlToVdom(__html__\`${html}\`).toElement()`
|
|
29
27
|
return `(() => { const __v__ = htmlToVdom(__html__\`${html}\`); __resolve_bem__(__v__, ${JSON.stringify(kebabCase(name))}); return __v__.toElement(); })()`
|
|
@@ -45,8 +43,26 @@ function templateReturnStart(body) {
|
|
|
45
43
|
return -1
|
|
46
44
|
}
|
|
47
45
|
|
|
46
|
+
function literalRanges(code) {
|
|
47
|
+
const tokens = tokenize(code);
|
|
48
|
+
const literal = t => t.type === "string" || t.type === "template" || t.type === "comment" || t.type === "regex";
|
|
49
|
+
|
|
50
|
+
return offset => {
|
|
51
|
+
let lo = 0, hi = tokens.length - 1;
|
|
52
|
+
while (lo <= hi) {
|
|
53
|
+
const mid = (lo + hi) >> 1;
|
|
54
|
+
const t = tokens[mid];
|
|
55
|
+
if (offset < t.start) hi = mid - 1;
|
|
56
|
+
else if (offset >= t.end) lo = mid + 1;
|
|
57
|
+
else return literal(t);
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
function parseComponentsEdits(code) {
|
|
49
64
|
const edits = [];
|
|
65
|
+
const inLiteral = literalRanges(code);
|
|
50
66
|
let i = 0;
|
|
51
67
|
|
|
52
68
|
while (i < code.length) {
|
|
@@ -60,6 +76,11 @@ function parseComponentsEdits(code) {
|
|
|
60
76
|
const tag = match[2] ?? null;
|
|
61
77
|
const start = i + match.index;
|
|
62
78
|
|
|
79
|
+
if (inLiteral(start + match[0].length - "component".length)) {
|
|
80
|
+
i = start + match[0].length;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
63
84
|
let p = start + match[0].length;
|
|
64
85
|
|
|
65
86
|
while (/\s/.test(code[p])) p++;
|
package/src/modulePaths.js
CHANGED
|
@@ -15,12 +15,18 @@ function readConfig() {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
function configName(key, fallback) {
|
|
19
|
+
const config = readConfig()
|
|
20
|
+
const names = config.names && typeof config.names === "object" ? config.names : {}
|
|
21
|
+
const value = names[key] ?? config[key]
|
|
22
|
+
return typeof value === "string" && value.trim() ? value : fallback
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
let projectPackagesCache = null
|
|
19
26
|
export function projectPackagesDir() {
|
|
20
27
|
if (projectPackagesCache) return projectPackagesCache
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
projectPackagesCache = path.resolve(typeof dir === "string" && dir.trim() ? dir : "packages")
|
|
29
|
+
projectPackagesCache = path.resolve(configName("packages", "packages"))
|
|
24
30
|
return projectPackagesCache
|
|
25
31
|
}
|
|
26
32
|
|
|
@@ -28,8 +34,7 @@ let distDirCache = null
|
|
|
28
34
|
export function distDirName() {
|
|
29
35
|
if (distDirCache) return distDirCache
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
distDirCache = typeof dir === "string" && dir.trim() ? dir : "slim-dist"
|
|
37
|
+
distDirCache = configName("dist", "slim-dist")
|
|
33
38
|
return distDirCache
|
|
34
39
|
}
|
|
35
40
|
|