@orgajs/orgx 2.6.1 → 2.6.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype-recma.d.ts","sourceRoot":"","sources":["rehype-recma.js"],"names":[],"mappings":"AAWA;;;;;;;GAOG;AACH,8CALW,OAAO,GAAG,IAAI,GAAG,SAAS,IAYnB,MALN,IAKU,KAHR,OAAO,
|
|
1
|
+
{"version":3,"file":"rehype-recma.d.ts","sourceRoot":"","sources":["rehype-recma.js"],"names":[],"mappings":"AAWA;;;;;;;GAOG;AACH,8CALW,OAAO,GAAG,IAAI,GAAG,SAAS,IAYnB,MALN,IAKU,KAHR,OAAO,CA+BpB;AA2BD,mDAAmD;AACnD,wBADW,OAAO,qBAAqB,EAAE,MAAM,CA8B9C;sBA5GY,OAAO,qBAAqB,EAAE,OAAO;6BADO,QAAQ;0BAD1C,MAAM"}
|
|
@@ -41,13 +41,9 @@ export default function rehypeRecma(options) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
],
|
|
44
|
-
source: {
|
|
45
|
-
type: 'Literal',
|
|
46
|
-
value: `${v}`,
|
|
47
|
-
raw: `'${v}'`
|
|
48
|
-
}
|
|
44
|
+
source: { type: 'Literal', value: `${v}` }
|
|
49
45
|
})
|
|
50
|
-
} else {
|
|
46
|
+
} else if (isValidName(k)) {
|
|
51
47
|
prepend.push(createExport(k, v))
|
|
52
48
|
}
|
|
53
49
|
})
|
|
@@ -123,6 +119,24 @@ function removeQuotes(text) {
|
|
|
123
119
|
return text.trim().replace(/^["'](.+(?=["']$))["']$/, '$1')
|
|
124
120
|
}
|
|
125
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Whether `name` can be declared with `export const`. Org keywords are `\w+`,
|
|
124
|
+
* so this only rejects names starting with a digit and reserved words.
|
|
125
|
+
*
|
|
126
|
+
* @param {string} name
|
|
127
|
+
*/
|
|
128
|
+
function isValidName(name) {
|
|
129
|
+
try {
|
|
130
|
+
Parser.parse(`const ${name} = 0`, {
|
|
131
|
+
sourceType: 'module',
|
|
132
|
+
ecmaVersion: 'latest'
|
|
133
|
+
})
|
|
134
|
+
return true
|
|
135
|
+
} catch {
|
|
136
|
+
return false
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
126
140
|
/**
|
|
127
141
|
* @param {string} k
|
|
128
142
|
* @param {any} v
|
|
@@ -131,8 +145,7 @@ function removeQuotes(text) {
|
|
|
131
145
|
function createExport(k, v) {
|
|
132
146
|
/** @type {(text: string) => Expression} */
|
|
133
147
|
const createLiteral = (text) => {
|
|
134
|
-
|
|
135
|
-
return { type: 'Literal', value, raw: `'${value}'` }
|
|
148
|
+
return { type: 'Literal', value: removeQuotes(`${text}`) }
|
|
136
149
|
}
|
|
137
150
|
/** @type {Expression} */
|
|
138
151
|
const init = Array.isArray(v)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orgajs/orgx",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "orga compiler with jsx support",
|
|
5
5
|
"author": "Xiaoxing Hu <hi@xiaoxing.dev>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@types/estree": "^1.0.6",
|
|
26
26
|
"@types/estree-jsx": "^1.0.5",
|
|
27
27
|
"@types/hast": "^3.0.4",
|
|
28
|
-
"@types/node": "^
|
|
28
|
+
"@types/node": "^25.3.2",
|
|
29
29
|
"@types/react": "^19.0.8",
|
|
30
30
|
"react": "^19.0.0",
|
|
31
31
|
"react-dom": "^19.0.0",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"unist-util-position-from-estree": "^2.0.0",
|
|
50
50
|
"unist-util-stringify-position": "^4.0.0",
|
|
51
51
|
"vfile": "^6.0.3",
|
|
52
|
-
"@orgajs/reorg-
|
|
53
|
-
"@orgajs/reorg-
|
|
52
|
+
"@orgajs/reorg-rehype": "^4.3.12",
|
|
53
|
+
"@orgajs/reorg-parse": "^4.4.1"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"test": "node --test tests/*.test.js"
|