@orgajs/orgx 2.5.2 → 2.6.1

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,UAOxB,IAAI,KAEF,OAAO,CAmCrB;AA2BD,mDAAmD;AACnD,wBADW,OAAO,qBAAqB,EAAE,MAAM,CA+B9C;sBAjHY,OAAO,qBAAqB,EAAE,OAAO;6BADO,QAAQ;0BAD1C,MAAM"}
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,CAmCpB;AA2BD,mDAAmD;AACnD,wBADW,OAAO,qBAAqB,EAAE,MAAM,CA8B9C;sBAhHY,OAAO,qBAAqB,EAAE,OAAO;6BADO,QAAQ;0BAD1C,MAAM"}
@@ -4,9 +4,9 @@
4
4
  * @typedef {import('hast-util-to-estree').Options} Options
5
5
  */
6
6
 
7
- import { toEstree } from 'hast-util-to-estree'
8
7
  import { Parser } from 'acorn'
9
8
  import jsx from 'acorn-jsx'
9
+ import { toEstree } from 'hast-util-to-estree'
10
10
  import renderError from '../util/render-error.js'
11
11
 
12
12
  /**
@@ -18,44 +18,44 @@ import renderError from '../util/render-error.js'
18
18
  * Transform.
19
19
  */
20
20
  export default function rehypeRecma(options) {
21
- /**
22
- * @param {Root} tree
23
- * Tree (hast).
24
- * @returns {Program}
25
- * Program (esast).
26
- */
27
- return function (tree) {
28
- const data = tree.data || {}
29
- /** @type {ModuleDeclaration[]} */
30
- const prepand = []
31
- Object.entries(data).forEach(([k, v]) => {
32
- if (k === 'layout') {
33
- prepand.push({
34
- type: 'ImportDeclaration',
35
- specifiers: [
36
- {
37
- type: 'ImportDefaultSpecifier',
38
- local: {
39
- type: 'Identifier',
40
- name: 'OrgLayout',
41
- },
42
- },
43
- ],
44
- source: {
45
- type: 'Literal',
46
- value: `${v}`,
47
- raw: `'${v}'`,
48
- },
49
- })
50
- } else {
51
- prepand.push(createExport(k, v))
52
- }
53
- })
21
+ /**
22
+ * @param {Root} tree
23
+ * Tree (hast).
24
+ * @returns {Program}
25
+ * Program (esast).
26
+ */
27
+ return function (tree) {
28
+ const data = tree.data || {}
29
+ /** @type {ModuleDeclaration[]} */
30
+ const prepend = []
31
+ Object.entries(data).forEach(([k, v]) => {
32
+ if (k === 'layout') {
33
+ prepend.push({
34
+ type: 'ImportDeclaration',
35
+ specifiers: [
36
+ {
37
+ type: 'ImportDefaultSpecifier',
38
+ local: {
39
+ type: 'Identifier',
40
+ name: 'OrgLayout'
41
+ }
42
+ }
43
+ ],
44
+ source: {
45
+ type: 'Literal',
46
+ value: `${v}`,
47
+ raw: `'${v}'`
48
+ }
49
+ })
50
+ } else {
51
+ prepend.push(createExport(k, v))
52
+ }
53
+ })
54
54
 
55
- const estree = toEstree(tree, { ...options, handlers: { jsx: handleJsx } })
56
- estree.body.unshift(...prepand)
57
- return estree
58
- }
55
+ const estree = toEstree(tree, { ...options, handlers: { jsx: handleJsx } })
56
+ estree.body.unshift(...prepend)
57
+ return estree
58
+ }
59
59
  }
60
60
 
61
61
  const jsxParser = Parser.extend(jsx())
@@ -65,55 +65,54 @@ const jsxParser = Parser.extend(jsx())
65
65
  * @returns {node is Program}
66
66
  */
67
67
  function isProgram(node) {
68
- return node.type === 'Program'
68
+ return node.type === 'Program'
69
69
  }
70
70
 
71
71
  /**
72
72
  * @param {string} code
73
73
  */
74
74
  function parse(code) {
75
- try {
76
- return jsxParser.parse(code, {
77
- sourceType: 'module',
78
- ecmaVersion: 2020,
79
- })
80
- } catch (err) {
81
- // @ts-ignore
82
- return renderError(err)
83
- }
75
+ try {
76
+ return jsxParser.parse(code, {
77
+ sourceType: 'module',
78
+ ecmaVersion: 2020
79
+ })
80
+ } catch (err) {
81
+ // @ts-expect-error
82
+ return renderError(err)
83
+ }
84
84
  }
85
85
 
86
86
  /** @type {import("hast-util-to-estree").Handle} */
87
87
  export const handleJsx = (node, state) => {
88
- let skipImport = false
89
- const estree = parse(node.value)
88
+ const skipImport = false
89
+ const estree = parse(node.value)
90
90
 
91
- /** @type {Expression[]} */
92
- const expressions = []
91
+ /** @type {Expression[]} */
92
+ const expressions = []
93
93
 
94
- if (isProgram(estree)) {
95
- estree.body.forEach((child) => {
96
- if (child.type === 'ImportDeclaration') {
97
- if (!skipImport) {
98
- state.esm.push(child)
99
- }
100
- return false
101
- } else if (child.type === 'ExpressionStatement') {
102
- expressions.push(child.expression)
103
- } else if (
104
- child.type === 'ExportDefaultDeclaration' ||
105
- child.type === 'ExportNamedDeclaration'
106
- ) {
107
- state.esm.push(child)
108
- } else {
109
- throw new Error(`unexpected node: ${child.type}`)
110
- }
111
- })
112
- }
94
+ if (isProgram(estree)) {
95
+ estree.body.forEach((child) => {
96
+ if (child.type === 'ImportDeclaration') {
97
+ if (!skipImport) {
98
+ state.esm.push(child)
99
+ }
100
+ } else if (child.type === 'ExpressionStatement') {
101
+ expressions.push(child.expression)
102
+ } else if (
103
+ child.type === 'ExportDefaultDeclaration' ||
104
+ child.type === 'ExportNamedDeclaration'
105
+ ) {
106
+ state.esm.push(child)
107
+ } else {
108
+ throw new Error(`unexpected node: ${child.type}`)
109
+ }
110
+ })
111
+ }
113
112
 
114
- // @ts-expect-error: array works
115
- // https://github.com/syntax-tree/hast-util-to-estree/blob/c0c4bd33583abade25c4f4e248a06cb1ec8c3aff/lib/state.js#L215
116
- return expressions
113
+ // @ts-expect-error: array works
114
+ // https://github.com/syntax-tree/hast-util-to-estree/blob/c0c4bd33583abade25c4f4e248a06cb1ec8c3aff/lib/state.js#L215
115
+ return expressions
117
116
  }
118
117
 
119
118
  /**
@@ -121,7 +120,7 @@ export const handleJsx = (node, state) => {
121
120
  * @returns {string}
122
121
  */
123
122
  function removeQuotes(text) {
124
- return text.trim().replace(/^["'](.+(?=["']$))["']$/, '$1')
123
+ return text.trim().replace(/^["'](.+(?=["']$))["']$/, '$1')
125
124
  }
126
125
 
127
126
  /**
@@ -130,32 +129,32 @@ function removeQuotes(text) {
130
129
  * @returns {ModuleDeclaration}
131
130
  */
132
131
  function createExport(k, v) {
133
- /** @type {(text: string) => Expression} */
134
- const createLiteral = (text) => {
135
- const value = removeQuotes(`${text}`)
136
- return { type: 'Literal', value, raw: `'${value}'` }
137
- }
138
- /** @type {Expression} */
139
- const init = Array.isArray(v)
140
- ? {
141
- type: 'ArrayExpression',
142
- elements: v.map(createLiteral),
143
- }
144
- : createLiteral(v)
145
- return {
146
- type: 'ExportNamedDeclaration',
147
- declaration: {
148
- type: 'VariableDeclaration',
149
- declarations: [
150
- {
151
- type: 'VariableDeclarator',
152
- id: { type: 'Identifier', name: k },
153
- init,
154
- },
155
- ],
156
- kind: 'const',
157
- },
158
- specifiers: [],
159
- source: null,
160
- }
132
+ /** @type {(text: string) => Expression} */
133
+ const createLiteral = (text) => {
134
+ const value = removeQuotes(`${text}`)
135
+ return { type: 'Literal', value, raw: `'${value}'` }
136
+ }
137
+ /** @type {Expression} */
138
+ const init = Array.isArray(v)
139
+ ? {
140
+ type: 'ArrayExpression',
141
+ elements: v.map(createLiteral)
142
+ }
143
+ : createLiteral(v)
144
+ return {
145
+ type: 'ExportNamedDeclaration',
146
+ declaration: {
147
+ type: 'VariableDeclaration',
148
+ declarations: [
149
+ {
150
+ type: 'VariableDeclarator',
151
+ id: { type: 'Identifier', name: k },
152
+ init
153
+ }
154
+ ],
155
+ kind: 'const'
156
+ },
157
+ specifiers: [],
158
+ source: null
159
+ }
161
160
  }
package/lib/run.js CHANGED
@@ -12,7 +12,7 @@ const AsyncFunction = Object.getPrototypeOf(run).constructor
12
12
  * Anything.
13
13
  */
14
14
  export async function run(file, options) {
15
- return new AsyncFunction(String(file))(options)
15
+ return new AsyncFunction(String(file))(options)
16
16
  }
17
17
 
18
18
  /**
@@ -26,6 +26,6 @@ export async function run(file, options) {
26
26
  * Anything.
27
27
  */
28
28
  export function runSync(file, options) {
29
- // eslint-disable-next-line no-new-func
30
- return new Function(String(file))(options)
29
+ // eslint-disable-next-line no-new-func
30
+ return new Function(String(file))(options)
31
31
  }
@@ -11,17 +11,17 @@
11
11
  * Nothing.
12
12
  */
13
13
  export function create(from, to) {
14
- /** @type {Array<keyof Node>} */
15
- // @ts-expect-error: `start`, `end`, `comments` are custom Acorn fields.
16
- const fields = ['start', 'end', 'loc', 'range', 'comments']
17
- let index = -1
14
+ /** @type {Array<keyof Node>} */
15
+ // @ts-expect-error: `start`, `end`, `comments` are custom Acorn fields.
16
+ const fields = ['start', 'end', 'loc', 'range', 'comments']
17
+ let index = -1
18
18
 
19
- while (++index < fields.length) {
20
- const field = fields[index]
19
+ while (++index < fields.length) {
20
+ const field = fields[index]
21
21
 
22
- if (field in from) {
23
- // @ts-expect-error: assume they’re settable.
24
- to[field] = from[field]
25
- }
26
- }
22
+ if (field in from) {
23
+ // @ts-expect-error: assume they’re settable.
24
+ to[field] = from[field]
25
+ }
26
+ }
27
27
  }
@@ -16,17 +16,17 @@
16
16
  * Expression.
17
17
  */
18
18
  export function declarationToExpression(declaration) {
19
- if (declaration.type === 'FunctionDeclaration') {
20
- return {...declaration, type: 'FunctionExpression'}
21
- }
19
+ if (declaration.type === 'FunctionDeclaration') {
20
+ return { ...declaration, type: 'FunctionExpression' }
21
+ }
22
22
 
23
- if (declaration.type === 'ClassDeclaration') {
24
- return {...declaration, type: 'ClassExpression'}
25
- /* Internal utility so the next shouldn’t happen or a maintainer is making a
26
- * mistake. */
27
- /* c8 ignore next 4 */
28
- }
23
+ if (declaration.type === 'ClassDeclaration') {
24
+ return { ...declaration, type: 'ClassExpression' }
25
+ /* Internal utility so the next shouldn’t happen or a maintainer is making a
26
+ * mistake. */
27
+ /* c8 ignore next 4 */
28
+ }
29
29
 
30
- // Probably `VariableDeclaration`.
31
- throw new Error('Cannot turn `' + declaration.type + '` into an expression')
30
+ // Probably `VariableDeclaration`.
31
+ throw new Error(`Cannot turn \`${declaration.type}\` into an expression`)
32
32
  }
@@ -12,9 +12,9 @@
12
12
  * Whether `node` is a declaration.
13
13
  */
14
14
  export function isDeclaration(node) {
15
- return Boolean(
16
- node.type === 'FunctionDeclaration' ||
17
- node.type === 'ClassDeclaration' ||
18
- node.type === 'VariableDeclaration'
19
- )
15
+ return Boolean(
16
+ node.type === 'FunctionDeclaration' ||
17
+ node.type === 'ClassDeclaration' ||
18
+ node.type === 'VariableDeclaration'
19
+ )
20
20
  }
@@ -9,7 +9,7 @@
9
9
  * @typedef {import('estree-jsx').VariableDeclarator} VariableDeclarator
10
10
  */
11
11
 
12
- import {create} from './estree-util-create.js'
12
+ import { create } from './estree-util-create.js'
13
13
 
14
14
  /**
15
15
  * @param {Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier>} specifiers
@@ -17,78 +17,78 @@ import {create} from './estree-util-create.js'
17
17
  * @returns {Array<VariableDeclarator>}
18
18
  */
19
19
  export function specifiersToDeclarations(specifiers, init) {
20
- let index = -1
21
- /** @type {Array<VariableDeclarator>} */
22
- const declarations = []
23
- /** @type {Array<ImportSpecifier | ImportDefaultSpecifier | ExportSpecifier>} */
24
- const otherSpecifiers = []
25
- // Can only be one according to JS syntax.
26
- /** @type {ImportNamespaceSpecifier | undefined} */
27
- let importNamespaceSpecifier
20
+ let index = -1
21
+ /** @type {Array<VariableDeclarator>} */
22
+ const declarations = []
23
+ /** @type {Array<ImportSpecifier | ImportDefaultSpecifier | ExportSpecifier>} */
24
+ const otherSpecifiers = []
25
+ // Can only be one according to JS syntax.
26
+ /** @type {ImportNamespaceSpecifier | undefined} */
27
+ let importNamespaceSpecifier
28
28
 
29
- while (++index < specifiers.length) {
30
- const specifier = specifiers[index]
29
+ while (++index < specifiers.length) {
30
+ const specifier = specifiers[index]
31
31
 
32
- if (specifier.type === 'ImportNamespaceSpecifier') {
33
- importNamespaceSpecifier = specifier
34
- } else {
35
- otherSpecifiers.push(specifier)
36
- }
37
- }
32
+ if (specifier.type === 'ImportNamespaceSpecifier') {
33
+ importNamespaceSpecifier = specifier
34
+ } else {
35
+ otherSpecifiers.push(specifier)
36
+ }
37
+ }
38
38
 
39
- if (importNamespaceSpecifier) {
40
- /** @type {VariableDeclarator} */
41
- const declarator = {
42
- type: 'VariableDeclarator',
43
- id: importNamespaceSpecifier.local,
44
- init
45
- }
46
- create(importNamespaceSpecifier, declarator)
47
- declarations.push(declarator)
48
- }
39
+ if (importNamespaceSpecifier) {
40
+ /** @type {VariableDeclarator} */
41
+ const declarator = {
42
+ type: 'VariableDeclarator',
43
+ id: importNamespaceSpecifier.local,
44
+ init
45
+ }
46
+ create(importNamespaceSpecifier, declarator)
47
+ declarations.push(declarator)
48
+ }
49
49
 
50
- declarations.push({
51
- type: 'VariableDeclarator',
52
- id: {
53
- type: 'ObjectPattern',
54
- properties: otherSpecifiers.map((specifier) => {
55
- /** @type {Identifier} */
56
- // @ts-expect-error: fine.
57
- let key =
58
- specifier.type === 'ImportSpecifier'
59
- ? specifier.imported
60
- : specifier.type === 'ExportSpecifier'
61
- ? specifier.exported
62
- : {type: 'Identifier', name: 'default'}
63
- let value = specifier.local
50
+ declarations.push({
51
+ type: 'VariableDeclarator',
52
+ id: {
53
+ type: 'ObjectPattern',
54
+ properties: otherSpecifiers.map((specifier) => {
55
+ /** @type {Identifier} */
56
+ // @ts-expect-error: fine.
57
+ let key =
58
+ specifier.type === 'ImportSpecifier'
59
+ ? specifier.imported
60
+ : specifier.type === 'ExportSpecifier'
61
+ ? specifier.exported
62
+ : { type: 'Identifier', name: 'default' }
63
+ let value = specifier.local
64
64
 
65
- // Switch them around if we’re exporting.
66
- if (specifier.type === 'ExportSpecifier') {
67
- value = key
68
- // @ts-expect-error: fine.
69
- key = specifier.local
70
- }
65
+ // Switch them around if we’re exporting.
66
+ if (specifier.type === 'ExportSpecifier') {
67
+ value = key
68
+ // @ts-expect-error: fine.
69
+ key = specifier.local
70
+ }
71
71
 
72
- /** @type {AssignmentProperty} */
73
- const property = {
74
- type: 'Property',
75
- kind: 'init',
76
- // @ts-expect-error: fine.
77
- shorthand: key.name === value.name,
78
- method: false,
79
- computed: false,
80
- key,
81
- // @ts-expect-error: fine.
82
- value
83
- }
84
- create(specifier, property)
85
- return property
86
- })
87
- },
88
- init: importNamespaceSpecifier
89
- ? {type: 'Identifier', name: importNamespaceSpecifier.local.name}
90
- : init
91
- })
72
+ /** @type {AssignmentProperty} */
73
+ const property = {
74
+ type: 'Property',
75
+ kind: 'init',
76
+ // @ts-expect-error: fine.
77
+ shorthand: key.name === value.name,
78
+ method: false,
79
+ computed: false,
80
+ key,
81
+ // @ts-expect-error: fine.
82
+ value
83
+ }
84
+ create(specifier, property)
85
+ return property
86
+ })
87
+ },
88
+ init: importNamespaceSpecifier
89
+ ? { type: 'Identifier', name: importNamespaceSpecifier.local.name }
90
+ : init
91
+ })
92
92
 
93
- return declarations
93
+ return declarations
94
94
  }
@@ -1 +1 @@
1
- {"version":3,"file":"estree-util-to-binary-addition.d.ts","sourceRoot":"","sources":["estree-util-to-binary-addition.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,8CAFW,KAAK,CAAC,UAAU,CAAC,+BAiB3B;yBArBY,OAAO,YAAY,EAAE,UAAU"}
1
+ {"version":3,"file":"estree-util-to-binary-addition.d.ts","sourceRoot":"","sources":["estree-util-to-binary-addition.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,8CAFW,KAAK,CAAC,UAAU,CAAC,+BAmB3B;yBAvBY,OAAO,YAAY,EAAE,UAAU"}
@@ -6,18 +6,20 @@
6
6
  * @param {Array<Expression>} expressions
7
7
  */
8
8
  export function toBinaryAddition(expressions) {
9
- let index = -1
10
- /** @type {Expression | undefined} */
11
- let left
9
+ let index = -1
10
+ /** @type {Expression | undefined} */
11
+ let left
12
12
 
13
- while (++index < expressions.length) {
14
- const right = expressions[index]
15
- left = left ? {type: 'BinaryExpression', left, operator: '+', right} : right
16
- }
13
+ while (++index < expressions.length) {
14
+ const right = expressions[index]
15
+ left = left
16
+ ? { type: 'BinaryExpression', left, operator: '+', right }
17
+ : right
18
+ }
17
19
 
18
- // Just for types.
19
- /* c8 ignore next */
20
- if (!left) throw new Error('Expected non-empty `expressions` to be passed')
20
+ // Just for types.
21
+ /* c8 ignore next */
22
+ if (!left) throw new Error('Expected non-empty `expressions` to be passed')
21
23
 
22
- return left
24
+ return left
23
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"estree-util-to-id-or-member-expression.d.ts","sourceRoot":"","sources":["estree-util-to-id-or-member-expression.js"],"names":[],"mappings":"AAsCE;;;GAGG;AACH,4CAHW,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GACpB,UAAU,GAAG,gBAAgB,CAwCzC;AA5DH,wCAEa,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,aAAa,GAAG,mBAAmB,CAO9E;yBA5BU,OAAO,YAAY,EAAE,UAAU;4BAC/B,OAAO,YAAY,EAAE,aAAa;kCAClC,OAAO,YAAY,EAAE,mBAAmB;sBACxC,OAAO,YAAY,EAAE,OAAO;+BAC5B,OAAO,YAAY,EAAE,gBAAgB"}
1
+ {"version":3,"file":"estree-util-to-id-or-member-expression.d.ts","sourceRoot":"","sources":["estree-util-to-id-or-member-expression.js"],"names":[],"mappings":"AAsCC;;;GAGG;AACH,4CAHW,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GACpB,UAAU,GAAG,gBAAgB,CA0CzC;AA9DF,wCAEY,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,aAAa,GAAG,mBAAmB,CAO9E;yBA5BW,OAAO,YAAY,EAAE,UAAU;4BAC/B,OAAO,YAAY,EAAE,aAAa;kCAClC,OAAO,YAAY,EAAE,mBAAmB;sBACxC,OAAO,YAAY,EAAE,OAAO;+BAC5B,OAAO,YAAY,EAAE,gBAAgB"}