@orgajs/orgx 2.6.0 → 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.
- package/index.js +1 -1
- package/lib/compile.d.ts.map +1 -1
- package/lib/compile.js +12 -6
- package/lib/core.js +5 -5
- package/lib/evaluate.js +4 -4
- package/lib/plugin/recma-build-jsx-transform.d.ts.map +1 -1
- package/lib/plugin/recma-build-jsx-transform.js +52 -52
- package/lib/plugin/recma-document.d.ts +1 -1
- package/lib/plugin/recma-document.js +546 -546
- package/lib/plugin/recma-jsx-rewrite.js +527 -527
- package/lib/plugin/rehype-recma.d.ts.map +1 -1
- package/lib/plugin/rehype-recma.js +115 -103
- package/lib/run.js +3 -3
- package/lib/util/estree-util-create.js +11 -11
- package/lib/util/estree-util-declaration-to-expression.js +11 -11
- package/lib/util/estree-util-is-declaration.js +5 -5
- package/lib/util/estree-util-specifiers-to-declarations.js +68 -68
- package/lib/util/estree-util-to-binary-addition.d.ts.map +1 -1
- package/lib/util/estree-util-to-binary-addition.js +13 -11
- package/lib/util/estree-util-to-id-or-member-expression.d.ts.map +1 -1
- package/lib/util/estree-util-to-id-or-member-expression.js +66 -64
- package/lib/util/render-error.js +83 -83
- package/lib/util/resolve-evaluate-options.js +31 -31
- package/lib/util/resolve-file-and-options.js +15 -15
- package/package.json +4 -4
|
@@ -7,27 +7,27 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
cont as esCont,
|
|
11
|
+
start as esStart,
|
|
12
|
+
name as isIdentifierName
|
|
13
13
|
} from 'estree-util-is-identifier-name'
|
|
14
14
|
|
|
15
15
|
export const toIdOrMemberExpression = toIdOrMemberExpressionFactory(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
'Identifier',
|
|
17
|
+
'MemberExpression',
|
|
18
|
+
isIdentifierName
|
|
19
19
|
)
|
|
20
20
|
|
|
21
21
|
export const toJsxIdOrMemberExpression =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
// @ts-expect-error: fine
|
|
23
|
+
/** @type {(ids: Array<string | number>) => JSXIdentifier | JSXMemberExpression)} */
|
|
24
|
+
(
|
|
25
|
+
toIdOrMemberExpressionFactory(
|
|
26
|
+
'JSXIdentifier',
|
|
27
|
+
'JSXMemberExpression',
|
|
28
|
+
isJsxIdentifierName
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* @param {string} idType
|
|
@@ -35,50 +35,52 @@ export const toJsxIdOrMemberExpression =
|
|
|
35
35
|
* @param {(value: string) => boolean} isIdentifier
|
|
36
36
|
*/
|
|
37
37
|
function toIdOrMemberExpressionFactory(idType, memberType, isIdentifier) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
return toIdOrMemberExpression
|
|
39
|
+
/**
|
|
40
|
+
* @param {Array<string | number>} ids
|
|
41
|
+
* @returns {Identifier | MemberExpression}
|
|
42
|
+
*/
|
|
43
|
+
function toIdOrMemberExpression(ids) {
|
|
44
|
+
let index = -1
|
|
45
|
+
/** @type {Identifier | Literal | MemberExpression | undefined} */
|
|
46
|
+
let object
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
while (++index < ids.length) {
|
|
49
|
+
const name = ids[index]
|
|
50
|
+
const valid = typeof name === 'string' && isIdentifier(name)
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
// A value of `asd.123` could be turned into `asd['123']` in the JS form,
|
|
53
|
+
// but JSX does not have a form for it, so throw.
|
|
54
|
+
/* c8 ignore next 3 */
|
|
55
|
+
if (idType === 'JSXIdentifier' && !valid) {
|
|
56
|
+
throw new Error(`Cannot turn \`${name}\` into a JSX identifier`)
|
|
57
|
+
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
/** @type {Identifier | Literal} */
|
|
60
|
+
// @ts-expect-error: JSX is fine.
|
|
61
|
+
const id = valid
|
|
62
|
+
? { type: idType, name }
|
|
63
|
+
: { type: 'Literal', value: name }
|
|
64
|
+
// @ts-expect-error: JSX is fine.
|
|
65
|
+
object = object
|
|
66
|
+
? {
|
|
67
|
+
type: memberType,
|
|
68
|
+
object,
|
|
69
|
+
property: id,
|
|
70
|
+
computed: id.type === 'Literal',
|
|
71
|
+
optional: false
|
|
72
|
+
}
|
|
73
|
+
: id
|
|
74
|
+
}
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
// Just for types.
|
|
77
|
+
/* c8 ignore next 3 */
|
|
78
|
+
if (!object) throw new Error('Expected non-empty `ids` to be passed')
|
|
79
|
+
if (object.type === 'Literal')
|
|
80
|
+
throw new Error('Expected identifier as left-most value')
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
return object
|
|
83
|
+
}
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
/**
|
|
@@ -86,17 +88,17 @@ function toIdOrMemberExpressionFactory(idType, memberType, isIdentifier) {
|
|
|
86
88
|
* @param {string} name
|
|
87
89
|
*/
|
|
88
90
|
function isJsxIdentifierName(name) {
|
|
89
|
-
|
|
91
|
+
let index = -1
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
while (++index < name.length) {
|
|
94
|
+
// We currently receive valid input, but this catches bugs and is needed
|
|
95
|
+
// when externalized.
|
|
96
|
+
/* c8 ignore next */
|
|
97
|
+
if (!(index ? jsxCont : esStart)(name.charCodeAt(index))) return false
|
|
98
|
+
}
|
|
97
99
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
// `false` if `name` is empty.
|
|
101
|
+
return index > 0
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
/**
|
|
@@ -104,5 +106,5 @@ function isJsxIdentifierName(name) {
|
|
|
104
106
|
* @param {number} code
|
|
105
107
|
*/
|
|
106
108
|
function jsxCont(code) {
|
|
107
|
-
|
|
109
|
+
return code === 45 /* `-` */ || esCont(code)
|
|
108
110
|
}
|
package/lib/util/render-error.js
CHANGED
|
@@ -5,87 +5,87 @@
|
|
|
5
5
|
* @returns {import('estree-jsx').Program}
|
|
6
6
|
*/
|
|
7
7
|
export default (error, bg = '#F44336', color = 'white') => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
8
|
+
return {
|
|
9
|
+
type: 'Program',
|
|
10
|
+
body: [
|
|
11
|
+
{
|
|
12
|
+
type: 'ExpressionStatement',
|
|
13
|
+
expression: {
|
|
14
|
+
type: 'JSXElement',
|
|
15
|
+
openingElement: {
|
|
16
|
+
type: 'JSXOpeningElement',
|
|
17
|
+
attributes: [
|
|
18
|
+
{
|
|
19
|
+
type: 'JSXAttribute',
|
|
20
|
+
name: {
|
|
21
|
+
type: 'JSXIdentifier',
|
|
22
|
+
name: 'style'
|
|
23
|
+
},
|
|
24
|
+
value: {
|
|
25
|
+
type: 'JSXExpressionContainer',
|
|
26
|
+
expression: {
|
|
27
|
+
type: 'ObjectExpression',
|
|
28
|
+
properties: [
|
|
29
|
+
{
|
|
30
|
+
type: 'Property',
|
|
31
|
+
method: false,
|
|
32
|
+
shorthand: false,
|
|
33
|
+
computed: false,
|
|
34
|
+
key: {
|
|
35
|
+
type: 'Identifier',
|
|
36
|
+
name: 'backgroundColor'
|
|
37
|
+
},
|
|
38
|
+
value: {
|
|
39
|
+
type: 'Literal',
|
|
40
|
+
value: bg,
|
|
41
|
+
raw: `'${bg}'`
|
|
42
|
+
},
|
|
43
|
+
kind: 'init'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: 'Property',
|
|
47
|
+
method: false,
|
|
48
|
+
shorthand: false,
|
|
49
|
+
computed: false,
|
|
50
|
+
key: {
|
|
51
|
+
type: 'Identifier',
|
|
52
|
+
name: 'color'
|
|
53
|
+
},
|
|
54
|
+
value: {
|
|
55
|
+
type: 'Literal',
|
|
56
|
+
value: color,
|
|
57
|
+
raw: `'${color}'`
|
|
58
|
+
},
|
|
59
|
+
kind: 'init'
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
name: {
|
|
67
|
+
type: 'JSXIdentifier',
|
|
68
|
+
name: 'pre'
|
|
69
|
+
},
|
|
70
|
+
selfClosing: false
|
|
71
|
+
},
|
|
72
|
+
closingElement: {
|
|
73
|
+
type: 'JSXClosingElement',
|
|
74
|
+
name: {
|
|
75
|
+
type: 'JSXIdentifier',
|
|
76
|
+
name: 'pre'
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
children: [
|
|
80
|
+
{
|
|
81
|
+
type: 'JSXText',
|
|
82
|
+
value: error.message,
|
|
83
|
+
raw: error.message
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
sourceType: 'module'
|
|
90
|
+
}
|
|
91
91
|
}
|
|
@@ -28,37 +28,37 @@
|
|
|
28
28
|
* @returns {{compiletime: ProcessorOptions, runtime: RunnerOptions}}
|
|
29
29
|
*/
|
|
30
30
|
export function resolveEvaluateOptions(options) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
const {
|
|
32
|
+
development,
|
|
33
|
+
Fragment,
|
|
34
|
+
jsx,
|
|
35
|
+
jsxs,
|
|
36
|
+
jsxDEV,
|
|
37
|
+
useOrgComponents,
|
|
38
|
+
...rest
|
|
39
|
+
} = options || {}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
if (!Fragment) throw new Error('Expected `Fragment` given to `evaluate`')
|
|
42
|
+
if (development) {
|
|
43
|
+
if (!jsxDEV) throw new Error('Expected `jsxDEV` given to `evaluate`')
|
|
44
|
+
} else {
|
|
45
|
+
if (!jsx) throw new Error('Expected `jsx` given to `evaluate`')
|
|
46
|
+
if (!jsxs) throw new Error('Expected `jsxs` given to `evaluate`')
|
|
47
|
+
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
return {
|
|
50
|
+
compiletime: {
|
|
51
|
+
...rest,
|
|
52
|
+
development,
|
|
53
|
+
outputFormat: 'function-body',
|
|
54
|
+
providerImportSource: useOrgComponents ? '#' : undefined
|
|
55
|
+
},
|
|
56
|
+
runtime: {
|
|
57
|
+
Fragment,
|
|
58
|
+
jsx,
|
|
59
|
+
jsxs,
|
|
60
|
+
jsxDEV,
|
|
61
|
+
useOrgComponents
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
64
|
}
|
|
@@ -15,15 +15,15 @@ import { VFile } from 'vfile'
|
|
|
15
15
|
* @returns {{file: VFile, options: ProcessorOptions}}
|
|
16
16
|
*/
|
|
17
17
|
export function resolveFileAndOptions(vfileCompatible, options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const file = looksLikeAVFile(vfileCompatible)
|
|
19
|
+
? vfileCompatible
|
|
20
|
+
: new VFile(vfileCompatible)
|
|
21
|
+
return {
|
|
22
|
+
file,
|
|
23
|
+
options: {
|
|
24
|
+
...options
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -31,10 +31,10 @@ export function resolveFileAndOptions(vfileCompatible, options) {
|
|
|
31
31
|
* @returns {value is VFile}
|
|
32
32
|
*/
|
|
33
33
|
function looksLikeAVFile(value) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
return Boolean(
|
|
35
|
+
value &&
|
|
36
|
+
typeof value === 'object' &&
|
|
37
|
+
'message' in value &&
|
|
38
|
+
'messages' in value
|
|
39
|
+
)
|
|
40
40
|
}
|
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"
|