@orgajs/orgx 2.2.1 → 2.3.0
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/dist/index.d.ts +7 -7
- package/dist/lib/compile.d.ts +6 -6
- package/dist/lib/core.d.ts +16 -14
- package/dist/lib/evaluate.d.ts +3 -3
- package/dist/lib/plugin/recma-build-jsx-transform.d.ts +20 -0
- package/dist/lib/plugin/recma-document.d.ts +24 -24
- package/dist/lib/plugin/recma-jsx-rewrite.d.ts +15 -15
- package/dist/lib/plugin/rehype-recma.d.ts +11 -46
- package/dist/lib/types.d.ts +0 -1
- package/dist/lib/util/estree-util-create.d.ts +1 -1
- package/dist/lib/util/estree-util-declaration-to-expression.d.ts +2 -2
- package/dist/lib/util/estree-util-is-declaration.d.ts +3 -3
- package/dist/lib/util/estree-util-specifiers-to-declarations.d.ts +8 -8
- package/dist/lib/util/estree-util-to-binary-addition.d.ts +1 -1
- package/dist/lib/util/estree-util-to-id-or-member-expression.d.ts +6 -6
- package/dist/lib/util/render-error.d.ts +1 -1
- package/dist/lib/util/resolve-evaluate-options.d.ts +2 -2
- package/dist/lib/util/resolve-file-and-options.d.ts +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/lib/core.js +20 -16
- package/lib/plugin/recma-build-jsx-transform.js +80 -0
- package/lib/plugin/recma-document.js +6 -5
- package/lib/plugin/rehype-recma.js +72 -129
- package/lib/util/estree-util-specifiers-to-declarations.js +4 -0
- package/package.json +22 -17
- package/dist/lib/condition.browser.d.ts +0 -1
- package/dist/lib/condition.d.ts +0 -1
- package/dist/lib/plugin/recma-jsx-build.d.ts +0 -14
- package/dist/lib/plugin/recma-stringify.d.ts +0 -13
- package/lib/condition.browser.js +0 -1
- package/lib/condition.js +0 -3
- package/lib/plugin/recma-jsx-build.js +0 -53
- package/lib/plugin/recma-stringify.js +0 -42
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { createProcessor } from "./lib/core.js";
|
|
2
|
-
export type ProcessorOptions = import(
|
|
3
|
-
export type CompileOptions = import(
|
|
4
|
-
export type EvaluateOptions = import(
|
|
5
|
-
export type OrgComponents = import(
|
|
6
|
-
export type OrgContent = import(
|
|
7
|
-
export type OrgModule = import(
|
|
8
|
-
export type OrgProps = import(
|
|
2
|
+
export type ProcessorOptions = import("./lib/core.js").ProcessorOptions;
|
|
3
|
+
export type CompileOptions = import("./lib/compile.js").CompileOptions;
|
|
4
|
+
export type EvaluateOptions = import("./lib/evaluate.js").EvaluateOptions;
|
|
5
|
+
export type OrgComponents = import("./lib/types.js").OrgComponents;
|
|
6
|
+
export type OrgContent = import("./lib/types.js").OrgContent;
|
|
7
|
+
export type OrgModule = import("./lib/types.js").OrgModule;
|
|
8
|
+
export type OrgProps = import("./lib/types.js").OrgProps;
|
|
9
9
|
export { compile, compileSync } from "./lib/compile.js";
|
|
10
10
|
export { evaluate, evaluateSync } from "./lib/evaluate.js";
|
|
11
11
|
export { run, runSync } from "./lib/run.js";
|
package/dist/lib/compile.d.ts
CHANGED
|
@@ -22,14 +22,14 @@ export function compile(vfileCompatible: VFileCompatible, compileOptions?: Compi
|
|
|
22
22
|
* File.
|
|
23
23
|
*/
|
|
24
24
|
export function compileSync(vfileCompatible: VFileCompatible, compileOptions?: CompileOptions | null | undefined): VFile;
|
|
25
|
-
export type VFile = import(
|
|
26
|
-
export type VFileCompatible = import(
|
|
27
|
-
export type PluginOptions = import(
|
|
28
|
-
export type BaseProcessorOptions = import(
|
|
25
|
+
export type VFile = import("vfile").VFile;
|
|
26
|
+
export type VFileCompatible = import("vfile").VFileCompatible;
|
|
27
|
+
export type PluginOptions = import("./core.js").PluginOptions;
|
|
28
|
+
export type BaseProcessorOptions = import("./core.js").BaseProcessorOptions;
|
|
29
29
|
/**
|
|
30
30
|
* Core configuration.
|
|
31
31
|
*/
|
|
32
|
-
export type CoreProcessorOptions = Omit<BaseProcessorOptions,
|
|
32
|
+
export type CoreProcessorOptions = Omit<BaseProcessorOptions, "format">;
|
|
33
33
|
/**
|
|
34
34
|
* Extra configuration.
|
|
35
35
|
*/
|
|
@@ -37,7 +37,7 @@ export type ExtraOptions = {
|
|
|
37
37
|
/**
|
|
38
38
|
* Format of `file`.
|
|
39
39
|
*/
|
|
40
|
-
format?:
|
|
40
|
+
format?: "detect" | "mdx" | "md" | null | undefined;
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
43
43
|
* Configuration.
|
package/dist/lib/core.d.ts
CHANGED
|
@@ -5,18 +5,17 @@
|
|
|
5
5
|
* 2. Transform through reorg (oast), rehype (hast), and recma (esast)
|
|
6
6
|
* 3. Serialize as JavaScript
|
|
7
7
|
*
|
|
8
|
-
* @param {ProcessorOptions | null | undefined} [options]
|
|
8
|
+
* @param {Readonly<ProcessorOptions> | null | undefined} [options]
|
|
9
9
|
* Configuration.
|
|
10
|
-
* @return {Processor}
|
|
10
|
+
* @return {Processor<Document, Program, Program, Program, string>}
|
|
11
11
|
* Processor.
|
|
12
|
+
|
|
12
13
|
*/
|
|
13
|
-
export function createProcessor(options?: ProcessorOptions | null | undefined): Processor
|
|
14
|
-
export type
|
|
15
|
-
export type
|
|
16
|
-
export type
|
|
17
|
-
export type
|
|
18
|
-
export type RecmaStringifyOptions = import('./plugin/recma-stringify.js').RecmaStringifyOptions;
|
|
19
|
-
export type RecmaJsxRewriteOptions = import('./plugin/recma-jsx-rewrite.js').RecmaJsxRewriteOptions;
|
|
14
|
+
export function createProcessor(options?: Readonly<ProcessorOptions> | null | undefined): Processor<Document, Program, Program, Program, string>;
|
|
15
|
+
export type RehypeRecmaOptions = import("./plugin/rehype-recma.js").Options;
|
|
16
|
+
export type RecmaDocumentOptions = import("./plugin/recma-document.js").RecmaDocumentOptions;
|
|
17
|
+
export type RecmaStringifyOptions = import("recma-stringify").Options;
|
|
18
|
+
export type RecmaJsxRewriteOptions = import("./plugin/recma-jsx-rewrite.js").RecmaJsxRewriteOptions;
|
|
20
19
|
/**
|
|
21
20
|
* Base configuration.
|
|
22
21
|
*/
|
|
@@ -33,25 +32,28 @@ export type BaseProcessorOptions = {
|
|
|
33
32
|
/**
|
|
34
33
|
* List of recma (esast, JavaScript) plugins.
|
|
35
34
|
*/
|
|
36
|
-
recmaPlugins?:
|
|
35
|
+
recmaPlugins?: PluggableList | null | undefined;
|
|
37
36
|
/**
|
|
38
37
|
* List of remark (mdast, markdown) plugins.
|
|
39
38
|
*/
|
|
40
|
-
reorgPlugins?:
|
|
39
|
+
reorgPlugins?: PluggableList | null | undefined;
|
|
41
40
|
/**
|
|
42
41
|
* List of rehype (hast, HTML) plugins.
|
|
43
42
|
*/
|
|
44
|
-
rehypePlugins?:
|
|
43
|
+
rehypePlugins?: PluggableList | null | undefined;
|
|
45
44
|
/**
|
|
46
45
|
* Options to pass through to `reorg-rehype`.
|
|
47
46
|
*/
|
|
48
|
-
reorgRehypeOptions?: import(
|
|
47
|
+
reorgRehypeOptions?: import("@orgajs/reorg-rehype").Options | null | undefined;
|
|
49
48
|
};
|
|
50
49
|
/**
|
|
51
50
|
* Configuration for internal plugins.
|
|
52
51
|
*/
|
|
53
|
-
export type PluginOptions = Omit<RehypeRecmaOptions & RecmaDocumentOptions & RecmaStringifyOptions & RecmaJsxRewriteOptions,
|
|
52
|
+
export type PluginOptions = Omit<RehypeRecmaOptions & RecmaDocumentOptions & RecmaStringifyOptions & RecmaJsxRewriteOptions, "outputFormat">;
|
|
54
53
|
/**
|
|
55
54
|
* Configuration for processor.
|
|
56
55
|
*/
|
|
57
56
|
export type ProcessorOptions = BaseProcessorOptions & PluginOptions;
|
|
57
|
+
import type { Program } from 'estree-jsx';
|
|
58
|
+
import type { Processor } from 'unified';
|
|
59
|
+
import type { PluggableList } from 'unified';
|
package/dist/lib/evaluate.d.ts
CHANGED
|
@@ -22,6 +22,6 @@ export function evaluate(vfileCompatible: VFileCompatible, evaluateOptions: Eval
|
|
|
22
22
|
* Export map.
|
|
23
23
|
*/
|
|
24
24
|
export function evaluateSync(vfileCompatible: VFileCompatible, evaluateOptions: EvaluateOptions): ExportMap;
|
|
25
|
-
export type ExportMap = import(
|
|
26
|
-
export type VFileCompatible = import(
|
|
27
|
-
export type EvaluateOptions = import(
|
|
25
|
+
export type ExportMap = import("./types.js").OrgModule;
|
|
26
|
+
export type VFileCompatible = import("vfile").VFileCompatible;
|
|
27
|
+
export type EvaluateOptions = import("./util/resolve-evaluate-options.js").EvaluateOptions;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin to change the tree after compiling JSX away.
|
|
3
|
+
*
|
|
4
|
+
* @param {Readonly<Options> | null | undefined} [options]
|
|
5
|
+
* Configuration (optional).
|
|
6
|
+
* @returns
|
|
7
|
+
* Transform.
|
|
8
|
+
*/
|
|
9
|
+
export function recmaBuildJsxTransform(options?: Readonly<Options> | null | undefined): (tree: Program) => undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for internal plugin `recma-build-jsx-transform`.
|
|
12
|
+
*/
|
|
13
|
+
export type Options = {
|
|
14
|
+
/**
|
|
15
|
+
* Whether to keep the import of the automatic runtime or get it from
|
|
16
|
+
* `arguments[0]` instead (default: `'program'`).
|
|
17
|
+
*/
|
|
18
|
+
outputFormat?: "function-body" | "program" | null | undefined;
|
|
19
|
+
};
|
|
20
|
+
import type { Program } from 'estree-jsx';
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export function recmaDocument(this: import("unified").Processor
|
|
2
|
-
export type Directive = import(
|
|
3
|
-
export type ExportAllDeclaration = import(
|
|
4
|
-
export type ExportDefaultDeclaration = import(
|
|
5
|
-
export type ExportNamedDeclaration = import(
|
|
6
|
-
export type ExportSpecifier = import(
|
|
7
|
-
export type Expression = import(
|
|
8
|
-
export type FunctionDeclaration = import(
|
|
9
|
-
export type ImportDeclaration = import(
|
|
10
|
-
export type ImportDefaultSpecifier = import(
|
|
11
|
-
export type ImportExpression = import(
|
|
12
|
-
export type ImportSpecifier = import(
|
|
13
|
-
export type Literal = import(
|
|
14
|
-
export type JSXElement = import(
|
|
15
|
-
export type ModuleDeclaration = import(
|
|
16
|
-
export type Node = import(
|
|
17
|
-
export type Program = import(
|
|
18
|
-
export type Property = import(
|
|
19
|
-
export type SimpleLiteral = import(
|
|
20
|
-
export type SpreadElement = import(
|
|
21
|
-
export type Statement = import(
|
|
22
|
-
export type VariableDeclarator = import(
|
|
1
|
+
export function recmaDocument(this: import("unified").Processor, ...parameters: [] | [RecmaDocumentOptions | null | undefined]): void | import("unified").Transformer<import("estree").Program, import("estree").Program> | undefined;
|
|
2
|
+
export type Directive = import("estree-jsx").Directive;
|
|
3
|
+
export type ExportAllDeclaration = import("estree-jsx").ExportAllDeclaration;
|
|
4
|
+
export type ExportDefaultDeclaration = import("estree-jsx").ExportDefaultDeclaration;
|
|
5
|
+
export type ExportNamedDeclaration = import("estree-jsx").ExportNamedDeclaration;
|
|
6
|
+
export type ExportSpecifier = import("estree-jsx").ExportSpecifier;
|
|
7
|
+
export type Expression = import("estree-jsx").Expression;
|
|
8
|
+
export type FunctionDeclaration = import("estree-jsx").FunctionDeclaration;
|
|
9
|
+
export type ImportDeclaration = import("estree-jsx").ImportDeclaration;
|
|
10
|
+
export type ImportDefaultSpecifier = import("estree-jsx").ImportDefaultSpecifier;
|
|
11
|
+
export type ImportExpression = import("estree-jsx").ImportExpression;
|
|
12
|
+
export type ImportSpecifier = import("estree-jsx").ImportSpecifier;
|
|
13
|
+
export type Literal = import("estree-jsx").Literal;
|
|
14
|
+
export type JSXElement = import("estree-jsx").JSXElement;
|
|
15
|
+
export type ModuleDeclaration = import("estree-jsx").ModuleDeclaration;
|
|
16
|
+
export type Node = import("estree-jsx").Node;
|
|
17
|
+
export type Program = import("estree-jsx").Program;
|
|
18
|
+
export type Property = import("estree-jsx").Property;
|
|
19
|
+
export type SimpleLiteral = import("estree-jsx").SimpleLiteral;
|
|
20
|
+
export type SpreadElement = import("estree-jsx").SpreadElement;
|
|
21
|
+
export type Statement = import("estree-jsx").Statement;
|
|
22
|
+
export type VariableDeclarator = import("estree-jsx").VariableDeclarator;
|
|
23
23
|
/**
|
|
24
24
|
* Configuration for internal plugin `recma-document`.
|
|
25
25
|
*/
|
|
@@ -29,7 +29,7 @@ export type RecmaDocumentOptions = {
|
|
|
29
29
|
* (and optionally provider) and export the content, or get values from
|
|
30
30
|
* `arguments` and return things.
|
|
31
31
|
*/
|
|
32
|
-
outputFormat?:
|
|
32
|
+
outputFormat?: "function-body" | "program" | null | undefined;
|
|
33
33
|
/**
|
|
34
34
|
* Whether to keep `import` (and `export … from`) statements or compile them
|
|
35
35
|
* to dynamic `import()` instead.
|
|
@@ -59,5 +59,5 @@ export type RecmaDocumentOptions = {
|
|
|
59
59
|
/**
|
|
60
60
|
* JSX runtime to use.
|
|
61
61
|
*/
|
|
62
|
-
jsxRuntime?:
|
|
62
|
+
jsxRuntime?: "automatic" | "classic" | null | undefined;
|
|
63
63
|
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export function recmaJsxRewrite(this: import("unified").Processor
|
|
2
|
-
export type Expression = import(
|
|
3
|
-
export type EstreeFunction = import(
|
|
4
|
-
export type Identifier = import(
|
|
5
|
-
export type ImportSpecifier = import(
|
|
6
|
-
export type JSXElement = import(
|
|
7
|
-
export type ModuleDeclaration = import(
|
|
8
|
-
export type Node = import(
|
|
9
|
-
export type ObjectPattern = import(
|
|
10
|
-
export type Program = import(
|
|
11
|
-
export type Property = import(
|
|
12
|
-
export type Statement = import(
|
|
13
|
-
export type VariableDeclarator = import(
|
|
14
|
-
export type Scope = import(
|
|
1
|
+
export function recmaJsxRewrite(this: import("unified").Processor, ...parameters: [] | [RecmaJsxRewriteOptions | null | undefined]): void | import("unified").Transformer<import("estree").Program, import("estree").Program> | undefined;
|
|
2
|
+
export type Expression = import("estree-jsx").Expression;
|
|
3
|
+
export type EstreeFunction = import("estree-jsx").Function;
|
|
4
|
+
export type Identifier = import("estree-jsx").Identifier;
|
|
5
|
+
export type ImportSpecifier = import("estree-jsx").ImportSpecifier;
|
|
6
|
+
export type JSXElement = import("estree-jsx").JSXElement;
|
|
7
|
+
export type ModuleDeclaration = import("estree-jsx").ModuleDeclaration;
|
|
8
|
+
export type Node = import("estree-jsx").Node;
|
|
9
|
+
export type ObjectPattern = import("estree-jsx").ObjectPattern;
|
|
10
|
+
export type Program = import("estree-jsx").Program;
|
|
11
|
+
export type Property = import("estree-jsx").Property;
|
|
12
|
+
export type Statement = import("estree-jsx").Statement;
|
|
13
|
+
export type VariableDeclarator = import("estree-jsx").VariableDeclarator;
|
|
14
|
+
export type Scope = import("periscopic").Scope & {
|
|
15
15
|
node: Node;
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
@@ -21,7 +21,7 @@ export type RecmaJsxRewriteOptions = {
|
|
|
21
21
|
/**
|
|
22
22
|
* Whether to use an import statement or `arguments[0]` to get the provider.
|
|
23
23
|
*/
|
|
24
|
-
outputFormat?:
|
|
24
|
+
outputFormat?: "function-body" | "program" | null | undefined;
|
|
25
25
|
/**
|
|
26
26
|
* Place to import a provider from.
|
|
27
27
|
*/
|
|
@@ -1,49 +1,14 @@
|
|
|
1
|
-
export function rehypeRecma(this: import("unified").Processor<void, import("hast").Root, void, void>, ...settings: [] | [Options | undefined]): void | import("unified").Transformer<import("hast").Root, import("estree").Program>;
|
|
2
|
-
export type Program = import('estree-jsx').Program;
|
|
3
|
-
export type Expression = import('estree-jsx').Expression;
|
|
4
|
-
export type ModuleDeclaration = import('estree-jsx').ModuleDeclaration;
|
|
5
|
-
export type Root = import('hast').Root;
|
|
6
|
-
export type Handle = import('hast-util-to-estree').Handle;
|
|
7
|
-
export type HastToEstreeOptions = import('hast-util-to-estree').Options;
|
|
8
1
|
/**
|
|
9
|
-
*
|
|
2
|
+
* Plugin to transform HTML (hast) to JS (estree).
|
|
10
3
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
4
|
+
* @param {Options | null | undefined} [options]
|
|
5
|
+
* Configuration (optional).
|
|
6
|
+
* @returns
|
|
7
|
+
* Transform.
|
|
13
8
|
*/
|
|
14
|
-
export
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
export type StylePropertyNameCase = 'css' | 'dom';
|
|
22
|
-
/**
|
|
23
|
-
* Configuration for internal plugin `rehype-recma`.
|
|
24
|
-
*/
|
|
25
|
-
export type MoreOptions = {
|
|
26
|
-
/**
|
|
27
|
-
* Specify casing to use for attribute names.
|
|
28
|
-
*
|
|
29
|
-
* This casing is used for hast elements, not for embedded Org JSX nodes
|
|
30
|
-
* (components that someone authored manually).
|
|
31
|
-
*/
|
|
32
|
-
elementAttributeNameCase?: ElementAttributeNameCase | undefined | null;
|
|
33
|
-
/**
|
|
34
|
-
* Specify casing to use for property names in `style` objects.
|
|
35
|
-
*
|
|
36
|
-
* This casing is used for hast elements, not for embedded Org JSX nodes
|
|
37
|
-
* (components that someone authored manually).
|
|
38
|
-
*/
|
|
39
|
-
stylePropertyNameCase?: StylePropertyNameCase | undefined | null;
|
|
40
|
-
/**
|
|
41
|
-
* - Whether to skip imports
|
|
42
|
-
*/
|
|
43
|
-
skipImport?: boolean | undefined;
|
|
44
|
-
/**
|
|
45
|
-
* - Specify which hast properties to parse as JSX.
|
|
46
|
-
*/
|
|
47
|
-
parseJSX?: string[] | undefined;
|
|
48
|
-
};
|
|
49
|
-
export type Options = HastToEstreeOptions & MoreOptions;
|
|
9
|
+
export default function rehypeRecma(options?: Options | null | undefined): (tree: Root) => Program;
|
|
10
|
+
/** @type {import("hast-util-to-estree").Handle} */
|
|
11
|
+
export const handleJsx: import("hast-util-to-estree").Handle;
|
|
12
|
+
export type Options = import("hast-util-to-estree").Options;
|
|
13
|
+
import type { Program } from 'estree';
|
|
14
|
+
import type { Root } from 'hast';
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
type FunctionComponent<Props> = (props: Props) => JSX.Element | null;
|
|
3
2
|
type ClassComponent<Props> = new (props: Props) => JSX.ElementClass;
|
|
4
3
|
type Component<Props> = FunctionComponent<Props> | ClassComponent<Props> | keyof JSX.IntrinsicElements;
|
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
* Expression.
|
|
16
16
|
*/
|
|
17
17
|
export function declarationToExpression(declaration: Declaration): Expression;
|
|
18
|
-
export type Declaration = import(
|
|
19
|
-
export type Expression = import(
|
|
18
|
+
export type Declaration = import("estree-jsx").Declaration;
|
|
19
|
+
export type Expression = import("estree-jsx").Expression;
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
* @returns {node is Declaration}
|
|
11
11
|
* Whether `node` is a declaration.
|
|
12
12
|
*/
|
|
13
|
-
export function isDeclaration(node: Node): node is
|
|
14
|
-
export type Node = import(
|
|
15
|
-
export type Declaration = import(
|
|
13
|
+
export function isDeclaration(node: Node): node is Declaration;
|
|
14
|
+
export type Node = import("estree-jsx").Node;
|
|
15
|
+
export type Declaration = import("estree-jsx").Declaration;
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* @returns {Array<VariableDeclarator>}
|
|
5
5
|
*/
|
|
6
6
|
export function specifiersToDeclarations(specifiers: Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier>, init: Expression): Array<VariableDeclarator>;
|
|
7
|
-
export type AssignmentProperty = import(
|
|
8
|
-
export type ExportSpecifier = import(
|
|
9
|
-
export type Expression = import(
|
|
10
|
-
export type Identifier = import(
|
|
11
|
-
export type ImportDefaultSpecifier = import(
|
|
12
|
-
export type ImportNamespaceSpecifier = import(
|
|
13
|
-
export type ImportSpecifier = import(
|
|
14
|
-
export type VariableDeclarator = import(
|
|
7
|
+
export type AssignmentProperty = import("estree-jsx").AssignmentProperty;
|
|
8
|
+
export type ExportSpecifier = import("estree-jsx").ExportSpecifier;
|
|
9
|
+
export type Expression = import("estree-jsx").Expression;
|
|
10
|
+
export type Identifier = import("estree-jsx").Identifier;
|
|
11
|
+
export type ImportDefaultSpecifier = import("estree-jsx").ImportDefaultSpecifier;
|
|
12
|
+
export type ImportNamespaceSpecifier = import("estree-jsx").ImportNamespaceSpecifier;
|
|
13
|
+
export type ImportSpecifier = import("estree-jsx").ImportSpecifier;
|
|
14
|
+
export type VariableDeclarator = import("estree-jsx").VariableDeclarator;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* @returns {Identifier | MemberExpression}
|
|
4
4
|
*/
|
|
5
5
|
export function toIdOrMemberExpression(ids: Array<string | number>): Identifier | MemberExpression;
|
|
6
|
-
export
|
|
7
|
-
export type Identifier = import(
|
|
8
|
-
export type JSXIdentifier = import(
|
|
9
|
-
export type JSXMemberExpression = import(
|
|
10
|
-
export type Literal = import(
|
|
11
|
-
export type MemberExpression = import(
|
|
6
|
+
export const toJsxIdOrMemberExpression: (ids: Array<string | number>) => JSXIdentifier | JSXMemberExpression;
|
|
7
|
+
export type Identifier = import("estree-jsx").Identifier;
|
|
8
|
+
export type JSXIdentifier = import("estree-jsx").JSXIdentifier;
|
|
9
|
+
export type JSXMemberExpression = import("estree-jsx").JSXMemberExpression;
|
|
10
|
+
export type Literal = import("estree-jsx").Literal;
|
|
11
|
+
export type MemberExpression = import("estree-jsx").MemberExpression;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function _default(error: SyntaxError, bg?: string, color?: string): import(
|
|
1
|
+
declare function _default(error: SyntaxError, bg?: string, color?: string): import("estree-jsx").Program;
|
|
2
2
|
export default _default;
|
|
@@ -30,7 +30,7 @@ export function resolveEvaluateOptions(options: EvaluateOptions | null | undefin
|
|
|
30
30
|
compiletime: ProcessorOptions;
|
|
31
31
|
runtime: RunnerOptions;
|
|
32
32
|
};
|
|
33
|
-
export type ProcessorOptions = import(
|
|
33
|
+
export type ProcessorOptions = import("../core.js").ProcessorOptions;
|
|
34
34
|
/**
|
|
35
35
|
* Configuration with JSX runtime.
|
|
36
36
|
*/
|
|
@@ -59,7 +59,7 @@ export type RunnerOptions = {
|
|
|
59
59
|
/**
|
|
60
60
|
* Compile configuration without JSX options for evaluation.
|
|
61
61
|
*/
|
|
62
|
-
export type EvaluateProcessorOptions = Omit<ProcessorOptions,
|
|
62
|
+
export type EvaluateProcessorOptions = Omit<ProcessorOptions, "jsx" | "jsxImportSource" | "jsxRuntime" | "pragma" | "pragmaFrag" | "pragmaImportSource" | "providerImportSource" | "outputFormat">;
|
|
63
63
|
/**
|
|
64
64
|
* Configuration for evaluation.
|
|
65
65
|
*/
|
|
@@ -10,7 +10,7 @@ export function resolveFileAndOptions(vfileCompatible: VFileCompatible, options?
|
|
|
10
10
|
file: VFile;
|
|
11
11
|
options: ProcessorOptions;
|
|
12
12
|
};
|
|
13
|
-
export type VFileCompatible = import(
|
|
14
|
-
export type ProcessorOptions = import(
|
|
15
|
-
export type CompileOptions = import(
|
|
13
|
+
export type VFileCompatible = import("vfile").VFileCompatible;
|
|
14
|
+
export type ProcessorOptions = import("../core.js").ProcessorOptions;
|
|
15
|
+
export type CompileOptions = import("../compile.js").CompileOptions;
|
|
16
16
|
import { VFile } from 'vfile';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../lib/compile.js","../lib/core.js","../lib/evaluate.js","../lib/run.js","../lib/types.ts","../lib/plugin/recma-build-jsx-transform.js","../lib/plugin/recma-document.js","../lib/plugin/recma-jsx-rewrite.js","../lib/plugin/rehype-recma.js","../lib/util/estree-util-create.js","../lib/util/estree-util-declaration-to-expression.js","../lib/util/estree-util-is-declaration.js","../lib/util/estree-util-specifiers-to-declarations.js","../lib/util/estree-util-to-binary-addition.js","../lib/util/estree-util-to-id-or-member-expression.js","../lib/util/render-error.js","../lib/util/resolve-evaluate-options.js","../lib/util/resolve-file-and-options.js","../index.js"],"version":"5.7.3"}
|
package/lib/core.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
* @
|
|
2
|
+
* @import {Program} from 'estree-jsx'
|
|
3
|
+
* @import {PluggableList, Processor} from 'unified'
|
|
4
4
|
* @typedef {import('./plugin/rehype-recma.js').Options} RehypeRecmaOptions
|
|
5
5
|
* @typedef {import('./plugin/recma-document.js').RecmaDocumentOptions} RecmaDocumentOptions
|
|
6
|
-
* @typedef {import('
|
|
6
|
+
* @typedef {import('recma-stringify').Options} RecmaStringifyOptions
|
|
7
7
|
* @typedef {import('./plugin/recma-jsx-rewrite.js').RecmaJsxRewriteOptions} RecmaJsxRewriteOptions
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
|
|
34
34
|
import { unified } from 'unified'
|
|
35
35
|
import reorgParse from '@orgajs/reorg-parse'
|
|
36
|
+
import recmaBuildJsx from 'recma-build-jsx'
|
|
37
|
+
import recmaJsx from 'recma-jsx'
|
|
38
|
+
import recmaStringify from 'recma-stringify'
|
|
36
39
|
import reorgRehype from '@orgajs/reorg-rehype'
|
|
37
|
-
import { recmaJsxBuild } from './plugin/recma-jsx-build.js'
|
|
38
40
|
import { recmaDocument } from './plugin/recma-document.js'
|
|
39
41
|
import { recmaJsxRewrite } from './plugin/recma-jsx-rewrite.js'
|
|
40
|
-
import
|
|
41
|
-
import {
|
|
42
|
-
// import { remarkMarkAndUnravel } from './plugin/remark-mark-and-unravel.js'
|
|
43
|
-
import { development as defaultDevelopment } from './condition.js'
|
|
42
|
+
import rehypeRecma from './plugin/rehype-recma.js'
|
|
43
|
+
import { recmaBuildJsxTransform } from './plugin/recma-build-jsx-transform.js'
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Pipeline to:
|
|
@@ -49,10 +49,11 @@ import { development as defaultDevelopment } from './condition.js'
|
|
|
49
49
|
* 2. Transform through reorg (oast), rehype (hast), and recma (esast)
|
|
50
50
|
* 3. Serialize as JavaScript
|
|
51
51
|
*
|
|
52
|
-
* @param {ProcessorOptions | null | undefined} [options]
|
|
52
|
+
* @param {Readonly<ProcessorOptions> | null | undefined} [options]
|
|
53
53
|
* Configuration.
|
|
54
|
-
* @return {Processor}
|
|
54
|
+
* @return {Processor<Document, Program, Program, Program, string>}
|
|
55
55
|
* Processor.
|
|
56
|
+
|
|
56
57
|
*/
|
|
57
58
|
export function createProcessor(options) {
|
|
58
59
|
const {
|
|
@@ -69,10 +70,7 @@ export function createProcessor(options) {
|
|
|
69
70
|
SourceMapGenerator,
|
|
70
71
|
...rest
|
|
71
72
|
} = options || {}
|
|
72
|
-
const dev =
|
|
73
|
-
development === null || development === undefined
|
|
74
|
-
? defaultDevelopment
|
|
75
|
-
: development
|
|
73
|
+
const dev = development ?? false
|
|
76
74
|
|
|
77
75
|
const pipeline = unified()
|
|
78
76
|
.use(reorgParse)
|
|
@@ -91,10 +89,16 @@ export function createProcessor(options) {
|
|
|
91
89
|
})
|
|
92
90
|
|
|
93
91
|
if (!jsx) {
|
|
94
|
-
pipeline
|
|
92
|
+
pipeline
|
|
93
|
+
.use(recmaBuildJsx, { development: dev, outputFormat })
|
|
94
|
+
.use(recmaBuildJsxTransform, { outputFormat })
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
pipeline
|
|
97
|
+
pipeline
|
|
98
|
+
.use(recmaJsx)
|
|
99
|
+
.use(recmaStringify, { SourceMapGenerator })
|
|
100
|
+
.use(recmaPlugins || [])
|
|
98
101
|
|
|
102
|
+
// @ts-expect-error: TS doesn’t get the plugins we added with if-statements.
|
|
99
103
|
return pipeline
|
|
100
104
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Program} from 'estree-jsx'
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef Options
|
|
7
|
+
* Configuration for internal plugin `recma-build-jsx-transform`.
|
|
8
|
+
* @property {'function-body' | 'program' | null | undefined} [outputFormat='program']
|
|
9
|
+
* Whether to keep the import of the automatic runtime or get it from
|
|
10
|
+
* `arguments[0]` instead (default: `'program'`).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {specifiersToDeclarations} from '../util/estree-util-specifiers-to-declarations.js'
|
|
14
|
+
import {toIdOrMemberExpression} from '../util/estree-util-to-id-or-member-expression.js'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Plugin to change the tree after compiling JSX away.
|
|
18
|
+
*
|
|
19
|
+
* @param {Readonly<Options> | null | undefined} [options]
|
|
20
|
+
* Configuration (optional).
|
|
21
|
+
* @returns
|
|
22
|
+
* Transform.
|
|
23
|
+
*/
|
|
24
|
+
export function recmaBuildJsxTransform(options) {
|
|
25
|
+
/* c8 ignore next -- always given in `@mdx-js/mdx` */
|
|
26
|
+
const {outputFormat} = options || {}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {Program} tree
|
|
30
|
+
* Tree.
|
|
31
|
+
* @returns {undefined}
|
|
32
|
+
* Nothing.
|
|
33
|
+
*/
|
|
34
|
+
return function (tree) {
|
|
35
|
+
// Remove the pragma comment that we injected ourselves as it is no longer
|
|
36
|
+
// needed.
|
|
37
|
+
// if (tree.comments) {
|
|
38
|
+
// tree.comments = tree.comments.filter(function (d) {
|
|
39
|
+
// return !d.data?._mdxIsPragmaComment
|
|
40
|
+
// })
|
|
41
|
+
// }
|
|
42
|
+
|
|
43
|
+
// When compiling to a function body, replace the import that was just
|
|
44
|
+
// generated, and get `jsx`, `jsxs`, and `Fragment` from `arguments[0]`
|
|
45
|
+
// instead.
|
|
46
|
+
if (outputFormat === 'function-body') {
|
|
47
|
+
let index = 0
|
|
48
|
+
|
|
49
|
+
// Skip directives: JS currently only has `use strict`, but Acorn allows
|
|
50
|
+
// arbitrary ones.
|
|
51
|
+
// Practically things like `use client` could be used?
|
|
52
|
+
while (index < tree.body.length) {
|
|
53
|
+
const child = tree.body[index]
|
|
54
|
+
if ('directive' in child && child.directive) {
|
|
55
|
+
index++
|
|
56
|
+
} else {
|
|
57
|
+
break
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const declaration = tree.body[index]
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
declaration &&
|
|
65
|
+
declaration.type === 'ImportDeclaration' &&
|
|
66
|
+
typeof declaration.source.value === 'string' &&
|
|
67
|
+
/\/jsx-(dev-)?runtime$/.test(declaration.source.value)
|
|
68
|
+
) {
|
|
69
|
+
tree.body[index] = {
|
|
70
|
+
type: 'VariableDeclaration',
|
|
71
|
+
kind: 'const',
|
|
72
|
+
declarations: specifiersToDeclarations(
|
|
73
|
+
declaration.specifiers,
|
|
74
|
+
toIdOrMemberExpression(['arguments', 0])
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -161,6 +161,7 @@ export function recmaDocument(options) {
|
|
|
161
161
|
{
|
|
162
162
|
type: 'VariableDeclarator',
|
|
163
163
|
id: { type: 'Identifier', name: 'OrgLayout' },
|
|
164
|
+
// @ts-expect-error
|
|
164
165
|
init: isDeclaration(child.declaration)
|
|
165
166
|
? declarationToExpression(child.declaration)
|
|
166
167
|
: child.declaration,
|
|
@@ -176,6 +177,7 @@ export function recmaDocument(options) {
|
|
|
176
177
|
|
|
177
178
|
// Remove `default` or `as default`, but not `default as`, specifier.
|
|
178
179
|
child.specifiers = child.specifiers.filter((specifier) => {
|
|
180
|
+
// @ts-expect-error
|
|
179
181
|
if (specifier.exported.name === 'default') {
|
|
180
182
|
if (layout) {
|
|
181
183
|
file.fail(
|
|
@@ -194,6 +196,7 @@ export function recmaDocument(options) {
|
|
|
194
196
|
const specifiers = []
|
|
195
197
|
|
|
196
198
|
// Default as default / something else as default.
|
|
199
|
+
// @ts-expect-error
|
|
197
200
|
if (specifier.local.name === 'default') {
|
|
198
201
|
specifiers.push({
|
|
199
202
|
type: 'ImportDefaultSpecifier',
|
|
@@ -247,7 +250,6 @@ export function recmaDocument(options) {
|
|
|
247
250
|
handleEsm(child)
|
|
248
251
|
} else if (
|
|
249
252
|
child.type === 'ExpressionStatement' &&
|
|
250
|
-
// @ts-expect-error types are wrong: `JSXFragment` is an `Expression`.
|
|
251
253
|
(child.expression.type === 'JSXFragment' ||
|
|
252
254
|
child.expression.type === 'JSXElement')
|
|
253
255
|
) {
|
|
@@ -364,6 +366,7 @@ export function recmaDocument(options) {
|
|
|
364
366
|
// export {a, b as c} from 'd'
|
|
365
367
|
// ```
|
|
366
368
|
for (child of node.specifiers) {
|
|
369
|
+
// @ts-expect-error
|
|
367
370
|
exportedIdentifiers.push(child.exported.name)
|
|
368
371
|
}
|
|
369
372
|
}
|
|
@@ -473,8 +476,10 @@ export function recmaDocument(options) {
|
|
|
473
476
|
replace = node.declaration
|
|
474
477
|
} else {
|
|
475
478
|
/** @type {Array<VariableDeclarator>} */
|
|
479
|
+
// @ts-expect-error
|
|
476
480
|
const declarators = node.specifiers
|
|
477
481
|
.filter(
|
|
482
|
+
// @ts-expect-error
|
|
478
483
|
(specifier) => specifier.local.name !== specifier.exported.name
|
|
479
484
|
)
|
|
480
485
|
.map((specifier) => ({
|
|
@@ -566,14 +571,10 @@ export function recmaDocument(options) {
|
|
|
566
571
|
// Unwrap a fragment of a single element.
|
|
567
572
|
if (
|
|
568
573
|
argument &&
|
|
569
|
-
// @ts-expect-error: fine.
|
|
570
574
|
argument.type === 'JSXFragment' &&
|
|
571
|
-
// @ts-expect-error: fine.
|
|
572
575
|
argument.children.length === 1 &&
|
|
573
|
-
// @ts-expect-error: fine.
|
|
574
576
|
argument.children[0].type === 'JSXElement'
|
|
575
577
|
) {
|
|
576
|
-
// @ts-expect-error: fine.
|
|
577
578
|
argument = argument.children[0]
|
|
578
579
|
}
|
|
579
580
|
|
|
@@ -1,43 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
* @
|
|
4
|
-
* @typedef {import('estree
|
|
5
|
-
* @typedef {import('hast').Root} Root
|
|
6
|
-
* @typedef {import('hast-util-to-estree').Handle} Handle
|
|
7
|
-
* @typedef {import('hast-util-to-estree').Options} HastToEstreeOptions
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @typedef {'html' | 'react'} ElementAttributeNameCase
|
|
12
|
-
* Specify casing to use for attribute names.
|
|
13
|
-
*
|
|
14
|
-
* HTML casing is for example `class`, `stroke-linecap`, `xml:lang`.
|
|
15
|
-
* React casing is for example `className`, `strokeLinecap`, `xmlLang`.
|
|
16
|
-
*
|
|
17
|
-
* @typedef {'css' | 'dom'} StylePropertyNameCase
|
|
18
|
-
* Casing to use for property names in `style` objects.
|
|
19
|
-
*
|
|
20
|
-
* CSS casing is for example `background-color` and `-webkit-line-clamp`.
|
|
21
|
-
* DOM casing is for example `backgroundColor` and `WebkitLineClamp`.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @typedef MoreOptions
|
|
26
|
-
* Configuration for internal plugin `rehype-recma`.
|
|
27
|
-
* @property {ElementAttributeNameCase | undefined | null} [elementAttributeNameCase='react']
|
|
28
|
-
* Specify casing to use for attribute names.
|
|
29
|
-
*
|
|
30
|
-
* This casing is used for hast elements, not for embedded Org JSX nodes
|
|
31
|
-
* (components that someone authored manually).
|
|
32
|
-
* @property {StylePropertyNameCase | undefined | null} [stylePropertyNameCase='dom']
|
|
33
|
-
* Specify casing to use for property names in `style` objects.
|
|
34
|
-
*
|
|
35
|
-
* This casing is used for hast elements, not for embedded Org JSX nodes
|
|
36
|
-
* (components that someone authored manually).
|
|
37
|
-
* @property {boolean} [skipImport=false] - Whether to skip imports
|
|
38
|
-
* @property {string[]} [parseJSX=['jsx.value']] - Specify which hast properties to parse as JSX.
|
|
39
|
-
*
|
|
40
|
-
* @typedef {HastToEstreeOptions & MoreOptions} Options
|
|
2
|
+
* @import {Root} from 'hast'
|
|
3
|
+
* @import {Program, Expression, ModuleDeclaration} from 'estree'
|
|
4
|
+
* @typedef {import('hast-util-to-estree').Options} Options
|
|
41
5
|
*/
|
|
42
6
|
|
|
43
7
|
import { toEstree } from 'hast-util-to-estree'
|
|
@@ -46,76 +10,68 @@ import jsx from 'acorn-jsx'
|
|
|
46
10
|
import renderError from '../util/render-error.js'
|
|
47
11
|
|
|
48
12
|
/**
|
|
49
|
-
*
|
|
50
|
-
* `hast-util-to-estree` does all the work for us!
|
|
13
|
+
* Plugin to transform HTML (hast) to JS (estree).
|
|
51
14
|
*
|
|
52
|
-
* @
|
|
15
|
+
* @param {Options | null | undefined} [options]
|
|
16
|
+
* Configuration (optional).
|
|
17
|
+
* @returns
|
|
18
|
+
* Transform.
|
|
53
19
|
*/
|
|
54
|
-
export function rehypeRecma(options
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
for (const p of parseJSX) {
|
|
63
|
-
const [key, ...rest] = p.split('.')
|
|
64
|
-
if (!key) {
|
|
65
|
-
throw new Error('somethings wrong')
|
|
66
|
-
}
|
|
67
|
-
const path = rest.length > 0 ? rest.join('.') : 'value'
|
|
68
|
-
handlers[key] = jsxHandle(path, skipImport)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return (tree) => {
|
|
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) {
|
|
72
28
|
const data = tree.data || {}
|
|
73
|
-
const { layout, ...otherData } = data
|
|
74
29
|
/** @type {ModuleDeclaration[]} */
|
|
75
30
|
const prepand = []
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
+
},
|
|
85
42
|
},
|
|
43
|
+
],
|
|
44
|
+
source: {
|
|
45
|
+
type: 'Literal',
|
|
46
|
+
value: `${v}`,
|
|
47
|
+
raw: `'${v}'`,
|
|
86
48
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
raw: `'${layout}'`,
|
|
92
|
-
},
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
Object.entries(otherData).forEach(([k, v]) => {
|
|
96
|
-
prepand.push(createExport(k, v))
|
|
49
|
+
})
|
|
50
|
+
} else {
|
|
51
|
+
prepand.push(createExport(k, v))
|
|
52
|
+
}
|
|
97
53
|
})
|
|
98
|
-
|
|
54
|
+
|
|
55
|
+
const estree = toEstree(tree, { ...options, handlers: { jsx: handleJsx } })
|
|
99
56
|
estree.body.unshift(...prepand)
|
|
100
57
|
return estree
|
|
101
58
|
}
|
|
102
59
|
}
|
|
103
60
|
|
|
61
|
+
const jsxParser = Parser.extend(jsx())
|
|
62
|
+
|
|
104
63
|
/**
|
|
105
|
-
* @param {
|
|
106
|
-
* @
|
|
107
|
-
* @returns {any}
|
|
64
|
+
* @param {import('acorn').Node | Program} node
|
|
65
|
+
* @returns {node is Program}
|
|
108
66
|
*/
|
|
109
|
-
function
|
|
110
|
-
return
|
|
67
|
+
function isProgram(node) {
|
|
68
|
+
return node.type === 'Program'
|
|
111
69
|
}
|
|
112
70
|
|
|
113
|
-
const jsxParser = Parser.extend(jsx())
|
|
114
|
-
|
|
115
71
|
/**
|
|
116
72
|
* @param {string} code
|
|
117
73
|
*/
|
|
118
|
-
|
|
74
|
+
function parse(code) {
|
|
119
75
|
try {
|
|
120
76
|
return jsxParser.parse(code, {
|
|
121
77
|
sourceType: 'module',
|
|
@@ -127,50 +83,37 @@ const parse = (code) => {
|
|
|
127
83
|
}
|
|
128
84
|
}
|
|
129
85
|
|
|
130
|
-
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
function isProgram(node) {
|
|
135
|
-
return node.type === 'Program'
|
|
136
|
-
}
|
|
86
|
+
/** @type {import("hast-util-to-estree").Handle} */
|
|
87
|
+
export const handleJsx = (node, state) => {
|
|
88
|
+
let skipImport = false
|
|
89
|
+
const estree = parse(node.value)
|
|
137
90
|
|
|
138
|
-
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
/** @type {Handle} */
|
|
146
|
-
const handle = (node, state) => {
|
|
147
|
-
const estree = parse(deepGet(path, node))
|
|
148
|
-
/** @type {Expression[]} */
|
|
149
|
-
const expressions = []
|
|
150
|
-
if (isProgram(estree)) {
|
|
151
|
-
estree.body.forEach((child) => {
|
|
152
|
-
if (child.type === 'ImportDeclaration') {
|
|
153
|
-
if (!skipImport) {
|
|
154
|
-
state.esm.push(child)
|
|
155
|
-
}
|
|
156
|
-
return false
|
|
157
|
-
} else if (child.type === 'ExpressionStatement') {
|
|
158
|
-
expressions.push(child.expression)
|
|
159
|
-
} else if (
|
|
160
|
-
child.type === 'ExportDefaultDeclaration' ||
|
|
161
|
-
child.type === 'ExportNamedDeclaration'
|
|
162
|
-
) {
|
|
91
|
+
/** @type {Expression[]} */
|
|
92
|
+
const expressions = []
|
|
93
|
+
|
|
94
|
+
if (isProgram(estree)) {
|
|
95
|
+
estree.body.forEach((child) => {
|
|
96
|
+
if (child.type === 'ImportDeclaration') {
|
|
97
|
+
if (!skipImport) {
|
|
163
98
|
state.esm.push(child)
|
|
164
|
-
} else {
|
|
165
|
-
throw new Error(`unexpected node: ${child.type}`)
|
|
166
99
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
+
})
|
|
172
112
|
}
|
|
173
|
-
|
|
113
|
+
|
|
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
|
|
174
117
|
}
|
|
175
118
|
|
|
176
119
|
/**
|
|
@@ -53,6 +53,7 @@ export function specifiersToDeclarations(specifiers, init) {
|
|
|
53
53
|
type: 'ObjectPattern',
|
|
54
54
|
properties: otherSpecifiers.map((specifier) => {
|
|
55
55
|
/** @type {Identifier} */
|
|
56
|
+
// @ts-expect-error: fine.
|
|
56
57
|
let key =
|
|
57
58
|
specifier.type === 'ImportSpecifier'
|
|
58
59
|
? specifier.imported
|
|
@@ -64,6 +65,7 @@ export function specifiersToDeclarations(specifiers, init) {
|
|
|
64
65
|
// Switch them around if we’re exporting.
|
|
65
66
|
if (specifier.type === 'ExportSpecifier') {
|
|
66
67
|
value = key
|
|
68
|
+
// @ts-expect-error: fine.
|
|
67
69
|
key = specifier.local
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -71,10 +73,12 @@ export function specifiersToDeclarations(specifiers, init) {
|
|
|
71
73
|
const property = {
|
|
72
74
|
type: 'Property',
|
|
73
75
|
kind: 'init',
|
|
76
|
+
// @ts-expect-error: fine.
|
|
74
77
|
shorthand: key.name === value.name,
|
|
75
78
|
method: false,
|
|
76
79
|
computed: false,
|
|
77
80
|
key,
|
|
81
|
+
// @ts-expect-error: fine.
|
|
78
82
|
value
|
|
79
83
|
}
|
|
80
84
|
create(specifier, property)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orgajs/orgx",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "orga compiler with jsx support",
|
|
5
5
|
"author": "Xiaoxing Hu <hi@xiaoxing.dev>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,43 +11,48 @@
|
|
|
11
11
|
"directory": "packages/orgx"
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
|
-
"
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./index.js"
|
|
16
|
+
},
|
|
15
17
|
"types": "dist/index.d.ts",
|
|
16
18
|
"browser": {
|
|
17
19
|
"./lib/condition.js": "./lib/condition.browser.js"
|
|
18
20
|
},
|
|
19
21
|
"files": [
|
|
20
|
-
"lib",
|
|
22
|
+
"lib/",
|
|
21
23
|
"dist",
|
|
22
24
|
"index.js",
|
|
23
25
|
"types.d.ts"
|
|
24
26
|
],
|
|
25
27
|
"devDependencies": {
|
|
26
|
-
"@types/estree": "^1.0.
|
|
27
|
-
"@types/estree-jsx": "^1.0.
|
|
28
|
-
"@types/hast": "^
|
|
28
|
+
"@types/estree": "^1.0.6",
|
|
29
|
+
"@types/estree-jsx": "^1.0.5",
|
|
30
|
+
"@types/hast": "^3.0.4",
|
|
29
31
|
"@types/node": "^20.5.7",
|
|
30
32
|
"@types/react": "^18.2.21",
|
|
31
33
|
"react": "^18.2.0",
|
|
32
34
|
"react-dom": "^18.2.0"
|
|
33
35
|
},
|
|
34
36
|
"dependencies": {
|
|
35
|
-
"acorn": "^8.
|
|
37
|
+
"acorn": "^8.14.0",
|
|
36
38
|
"acorn-jsx": "^5.3.2",
|
|
37
39
|
"astring": "^1.8.6",
|
|
38
|
-
"estree-util-build-jsx": "
|
|
39
|
-
"estree-util-is-identifier-name": "
|
|
40
|
-
"estree-util-to-js": "^
|
|
40
|
+
"estree-util-build-jsx": "3.0.1",
|
|
41
|
+
"estree-util-is-identifier-name": "3.0.0",
|
|
42
|
+
"estree-util-to-js": "^2.0.0",
|
|
41
43
|
"estree-walker": "3.0.3",
|
|
42
|
-
"hast-util-to-estree": "^
|
|
44
|
+
"hast-util-to-estree": "^3.1.1",
|
|
43
45
|
"periscopic": "3.1.0",
|
|
46
|
+
"recma-build-jsx": "^1.0.0",
|
|
47
|
+
"recma-jsx": "^1.0.0",
|
|
48
|
+
"recma-stringify": "^1.0.0",
|
|
44
49
|
"source-map": "^0.7.4",
|
|
45
|
-
"unified": "^
|
|
46
|
-
"unist-util-position-from-estree": "^
|
|
47
|
-
"unist-util-stringify-position": "^
|
|
48
|
-
"vfile": "^
|
|
49
|
-
"@orgajs/reorg-parse": "^4.
|
|
50
|
-
"@orgajs/reorg-rehype": "^4.
|
|
50
|
+
"unified": "^11.0.5",
|
|
51
|
+
"unist-util-position-from-estree": "^2.0.0",
|
|
52
|
+
"unist-util-stringify-position": "^4.0.0",
|
|
53
|
+
"vfile": "^6.0.3",
|
|
54
|
+
"@orgajs/reorg-parse": "^4.2.0",
|
|
55
|
+
"@orgajs/reorg-rehype": "^4.2.0"
|
|
51
56
|
},
|
|
52
57
|
"scripts": {
|
|
53
58
|
"clean": "tsc --build --clean",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const development: false;
|
package/dist/lib/condition.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const development: boolean;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function recmaJsxBuild(this: import("unified").Processor<void, import("estree").Program, void, void>, ...settings: [RecmaJsxBuildOptions | null | undefined] | []): void | import("unified").Transformer<import("estree").Program, import("estree").Program>;
|
|
2
|
-
export type Program = import('estree-jsx').Program;
|
|
3
|
-
export type BuildJsxOptions = import('estree-util-build-jsx').BuildJsxOptions;
|
|
4
|
-
/**
|
|
5
|
-
* Configuration for internal plugin `recma-jsx-build`.
|
|
6
|
-
*/
|
|
7
|
-
export type ExtraOptions = {
|
|
8
|
-
/**
|
|
9
|
-
* Whether to keep the import of the automatic runtime or get it from
|
|
10
|
-
* `arguments[0]` instead.
|
|
11
|
-
*/
|
|
12
|
-
outputFormat?: 'function-body' | 'program' | null | undefined;
|
|
13
|
-
};
|
|
14
|
-
export type RecmaJsxBuildOptions = BuildJsxOptions & ExtraOptions;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function recmaStringify(this: import("unified").Processor<void, import("estree").Program, import("estree").Program, string>, ...settings: [] | [RecmaStringifyOptions | null | undefined]): void;
|
|
2
|
-
export type Program = import('estree-jsx').Program;
|
|
3
|
-
export type SourceMapGenerator = typeof import('source-map').SourceMapGenerator;
|
|
4
|
-
/**
|
|
5
|
-
* Configuration for internal plugin `recma-stringify`.
|
|
6
|
-
*/
|
|
7
|
-
export type RecmaStringifyOptions = {
|
|
8
|
-
/**
|
|
9
|
-
* Generate a source map by passing a `SourceMapGenerator` from `source-map`
|
|
10
|
-
* in.
|
|
11
|
-
*/
|
|
12
|
-
SourceMapGenerator?: SourceMapGenerator | null | undefined;
|
|
13
|
-
};
|
package/lib/condition.browser.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const development = false
|
package/lib/condition.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {import('estree-jsx').Program} Program
|
|
3
|
-
* @typedef {import('estree-util-build-jsx').BuildJsxOptions} BuildJsxOptions
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef ExtraOptions
|
|
8
|
-
* Configuration for internal plugin `recma-jsx-build`.
|
|
9
|
-
* @property {'function-body' | 'program' | null | undefined} [outputFormat='program']
|
|
10
|
-
* Whether to keep the import of the automatic runtime or get it from
|
|
11
|
-
* `arguments[0]` instead.
|
|
12
|
-
*
|
|
13
|
-
* @typedef {BuildJsxOptions & ExtraOptions} RecmaJsxBuildOptions
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { buildJsx } from 'estree-util-build-jsx'
|
|
17
|
-
import { specifiersToDeclarations } from '../util/estree-util-specifiers-to-declarations.js'
|
|
18
|
-
import { toIdOrMemberExpression } from '../util/estree-util-to-id-or-member-expression.js'
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A plugin to build JSX into function calls.
|
|
22
|
-
* `estree-util-build-jsx` does all the work for us!
|
|
23
|
-
*
|
|
24
|
-
* @type {import('unified').Plugin<[RecmaJsxBuildOptions | null | undefined] | [], Program>}
|
|
25
|
-
*/
|
|
26
|
-
export function recmaJsxBuild(options) {
|
|
27
|
-
// Always given inside `@orgajs/orgx`
|
|
28
|
-
const { development, outputFormat } = options || {}
|
|
29
|
-
|
|
30
|
-
return (tree, file) => {
|
|
31
|
-
buildJsx(tree, { development, filePath: file.history[0] })
|
|
32
|
-
|
|
33
|
-
// When compiling to a function body, replace the import that was just
|
|
34
|
-
// generated, and get `jsx`, `jsxs`, and `Fragment` from `arguments[0]`
|
|
35
|
-
// instead.
|
|
36
|
-
if (
|
|
37
|
-
outputFormat === 'function-body' &&
|
|
38
|
-
tree.body[0] &&
|
|
39
|
-
tree.body[0].type === 'ImportDeclaration' &&
|
|
40
|
-
typeof tree.body[0].source.value === 'string' &&
|
|
41
|
-
/\/jsx-(dev-)?runtime$/.test(tree.body[0].source.value)
|
|
42
|
-
) {
|
|
43
|
-
tree.body[0] = {
|
|
44
|
-
type: 'VariableDeclaration',
|
|
45
|
-
kind: 'const',
|
|
46
|
-
declarations: specifiersToDeclarations(
|
|
47
|
-
tree.body[0].specifiers,
|
|
48
|
-
toIdOrMemberExpression(['arguments', 0])
|
|
49
|
-
),
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {import('estree-jsx').Program} Program
|
|
3
|
-
* @typedef {typeof import('source-map').SourceMapGenerator} SourceMapGenerator
|
|
4
|
-
*
|
|
5
|
-
* @typedef RecmaStringifyOptions
|
|
6
|
-
* Configuration for internal plugin `recma-stringify`.
|
|
7
|
-
* @property {SourceMapGenerator | null | undefined} [SourceMapGenerator]
|
|
8
|
-
* Generate a source map by passing a `SourceMapGenerator` from `source-map`
|
|
9
|
-
* in.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { toJs, jsx } from 'estree-util-to-js'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A plugin that adds an esast compiler: a small wrapper around `astring` to add
|
|
16
|
-
* support for serializing JSX.
|
|
17
|
-
*
|
|
18
|
-
* @this {import('unified').Processor}
|
|
19
|
-
* @type {import('unified').Plugin<[RecmaStringifyOptions | null | undefined] | [], Program, string>}
|
|
20
|
-
*/
|
|
21
|
-
export function recmaStringify(options) {
|
|
22
|
-
// Always given inside `@mdx-js/mdx`
|
|
23
|
-
/* c8 ignore next */
|
|
24
|
-
const { SourceMapGenerator } = options || {}
|
|
25
|
-
|
|
26
|
-
Object.assign(this, { Compiler: compiler })
|
|
27
|
-
|
|
28
|
-
/** @type {import('unified').CompilerFunction<Program, string>} */
|
|
29
|
-
function compiler(tree, file) {
|
|
30
|
-
const result = SourceMapGenerator
|
|
31
|
-
? toJs(tree, {
|
|
32
|
-
filePath: file.path || 'unknown.mdx',
|
|
33
|
-
SourceMapGenerator,
|
|
34
|
-
handlers: jsx,
|
|
35
|
-
})
|
|
36
|
-
: toJs(tree, { handlers: jsx })
|
|
37
|
-
|
|
38
|
-
file.map = result.map
|
|
39
|
-
|
|
40
|
-
return result.value
|
|
41
|
-
}
|
|
42
|
-
}
|