@herb-tools/core 0.8.9 → 0.9.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/herb-core.browser.js +22025 -129
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +22100 -130
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +22025 -129
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +22100 -130
- package/dist/herb-core.umd.js.map +1 -1
- package/dist/types/ast-utils.d.ts +185 -3
- package/dist/types/backend.d.ts +6 -6
- package/dist/types/errors.d.ts +267 -25
- package/dist/types/extract-ruby-options.d.ts +6 -0
- package/dist/types/herb-backend.d.ts +15 -7
- package/dist/types/index.d.ts +2 -0
- package/dist/types/node-type-guards.d.ts +95 -32
- package/dist/types/nodes.d.ts +354 -49
- package/dist/types/parse-result.d.ts +7 -1
- package/dist/types/parser-options.d.ts +30 -2
- package/dist/types/prism/index.d.ts +28 -0
- package/dist/types/prism/inspect.d.ts +3 -0
- package/dist/types/util.d.ts +0 -1
- package/dist/types/visitor.d.ts +15 -1
- package/package.json +4 -1
- package/src/ast-utils.ts +564 -7
- package/src/backend.ts +7 -7
- package/src/errors.ts +830 -76
- package/src/extract-ruby-options.ts +11 -0
- package/src/herb-backend.ts +30 -15
- package/src/index.ts +2 -0
- package/src/node-type-guards.ts +240 -33
- package/src/nodes.ts +1081 -192
- package/src/parse-result.ts +11 -0
- package/src/parser-options.ts +56 -2
- package/src/prism/index.ts +44 -0
- package/src/prism/inspect.ts +118 -0
- package/src/util.ts +0 -12
- package/src/visitor.ts +51 -1
|
@@ -2,15 +2,18 @@ import { Result } from "./result.js";
|
|
|
2
2
|
import { DocumentNode } from "./nodes.js";
|
|
3
3
|
import { HerbError } from "./errors.js";
|
|
4
4
|
import { HerbWarning } from "./warning.js";
|
|
5
|
+
import { ParserOptions } from "./parser-options.js";
|
|
5
6
|
import type { SerializedHerbError } from "./errors.js";
|
|
6
7
|
import type { SerializedHerbWarning } from "./warning.js";
|
|
7
8
|
import type { SerializedDocumentNode } from "./nodes.js";
|
|
9
|
+
import type { SerializedParserOptions } from "./parser-options.js";
|
|
8
10
|
import type { Visitor } from "./visitor.js";
|
|
9
11
|
export type SerializedParseResult = {
|
|
10
12
|
value: SerializedDocumentNode;
|
|
11
13
|
source: string;
|
|
12
14
|
warnings: SerializedHerbWarning[];
|
|
13
15
|
errors: SerializedHerbError[];
|
|
16
|
+
options: SerializedParserOptions;
|
|
14
17
|
};
|
|
15
18
|
/**
|
|
16
19
|
* Represents the result of a parsing operation, extending the base `Result` class.
|
|
@@ -19,6 +22,8 @@ export type SerializedParseResult = {
|
|
|
19
22
|
export declare class ParseResult extends Result {
|
|
20
23
|
/** The document node generated from the source code. */
|
|
21
24
|
readonly value: DocumentNode;
|
|
25
|
+
/** The parser options used during parsing. */
|
|
26
|
+
readonly options: ParserOptions;
|
|
22
27
|
/**
|
|
23
28
|
* Creates a `ParseResult` instance from a serialized result.
|
|
24
29
|
* @param result - The serialized parse result containing the value and source.
|
|
@@ -31,8 +36,9 @@ export declare class ParseResult extends Result {
|
|
|
31
36
|
* @param source - The source code that was parsed.
|
|
32
37
|
* @param warnings - An array of warnings encountered during parsing.
|
|
33
38
|
* @param errors - An array of errors encountered during parsing.
|
|
39
|
+
* @param options - The parser options used during parsing.
|
|
34
40
|
*/
|
|
35
|
-
constructor(value: DocumentNode, source: string, warnings?: HerbWarning[], errors?: HerbError[]);
|
|
41
|
+
constructor(value: DocumentNode, source: string, warnings?: HerbWarning[], errors?: HerbError[], options?: ParserOptions);
|
|
36
42
|
/**
|
|
37
43
|
* Determines if the parsing failed.
|
|
38
44
|
* @returns `true` if there are errors, otherwise `false`.
|
|
@@ -1,4 +1,32 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface ParseOptions {
|
|
2
2
|
track_whitespace?: boolean;
|
|
3
|
+
analyze?: boolean;
|
|
4
|
+
strict?: boolean;
|
|
5
|
+
action_view_helpers?: boolean;
|
|
6
|
+
prism_nodes?: boolean;
|
|
7
|
+
prism_nodes_deep?: boolean;
|
|
8
|
+
prism_program?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type SerializedParserOptions = Required<ParseOptions>;
|
|
11
|
+
export declare const DEFAULT_PARSER_OPTIONS: SerializedParserOptions;
|
|
12
|
+
/**
|
|
13
|
+
* Represents the parser options used during parsing.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ParserOptions {
|
|
16
|
+
/** Whether strict mode was enabled during parsing. */
|
|
17
|
+
readonly strict: boolean;
|
|
18
|
+
/** Whether whitespace tracking was enabled during parsing. */
|
|
19
|
+
readonly track_whitespace: boolean;
|
|
20
|
+
/** Whether analysis was performed during parsing. */
|
|
21
|
+
readonly analyze: boolean;
|
|
22
|
+
/** Whether ActionView tag helper transformation was enabled during parsing. */
|
|
23
|
+
readonly action_view_helpers: boolean;
|
|
24
|
+
/** Whether Prism node serialization was enabled during parsing. */
|
|
25
|
+
readonly prism_nodes: boolean;
|
|
26
|
+
/** Whether deep Prism node serialization was enabled during parsing. */
|
|
27
|
+
readonly prism_nodes_deep: boolean;
|
|
28
|
+
/** Whether the full Prism ProgramNode was serialized on the DocumentNode. */
|
|
29
|
+
readonly prism_program: boolean;
|
|
30
|
+
static from(options: SerializedParserOptions): ParserOptions;
|
|
31
|
+
constructor(options?: ParseOptions);
|
|
3
32
|
}
|
|
4
|
-
export declare const DEFAULT_PARSER_OPTIONS: ParserOptions;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ParseResult as PrismParseResult } from "@ruby/prism/src/deserialize.js";
|
|
2
|
+
export * as PrismNodes from "@ruby/prism/src/nodes.js";
|
|
3
|
+
export { Visitor as PrismVisitor, BasicVisitor as PrismBasicVisitor } from "@ruby/prism/src/visitor.js";
|
|
4
|
+
export type PrismNode = any;
|
|
5
|
+
export type PrismLocation = {
|
|
6
|
+
startOffset: number;
|
|
7
|
+
length: number;
|
|
8
|
+
};
|
|
9
|
+
export type { PrismParseResult };
|
|
10
|
+
export { inspectPrismNode, inspectPrismSerialized } from "./inspect.js";
|
|
11
|
+
/**
|
|
12
|
+
* Deserialize a Prism parse result from the raw bytes produced by pm_serialize().
|
|
13
|
+
*
|
|
14
|
+
* @param bytes - The serialized bytes (from prism_serialized field on ERB nodes)
|
|
15
|
+
* @param source - The original source string that was parsed
|
|
16
|
+
* @returns The deserialized Prism ParseResult containing the AST
|
|
17
|
+
*/
|
|
18
|
+
export declare function deserializePrismParseResult(bytes: Uint8Array, source: string): PrismParseResult;
|
|
19
|
+
/**
|
|
20
|
+
* Deserialize a Prism node from the raw bytes produced by pm_serialize().
|
|
21
|
+
* pm_serialize() serializes a single node subtree, so the ParseResult's
|
|
22
|
+
* value is the Prism node directly (not wrapped in ProgramNode).
|
|
23
|
+
*
|
|
24
|
+
* @param bytes - The serialized bytes (from prism_serialized field on ERB nodes)
|
|
25
|
+
* @param source - The original source string that was parsed
|
|
26
|
+
* @returns The Prism node, or null if deserialization fails
|
|
27
|
+
*/
|
|
28
|
+
export declare function deserializePrismNode(bytes: Uint8Array, source: string): PrismNode | null;
|
package/dist/types/util.d.ts
CHANGED
package/dist/types/visitor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node, ERBNode, DocumentNode, LiteralNode, HTMLOpenTagNode, HTMLCloseTagNode, HTMLElementNode, HTMLAttributeValueNode, HTMLAttributeNameNode, HTMLAttributeNode, HTMLTextNode, HTMLCommentNode, HTMLDoctypeNode, XMLDeclarationNode, CDATANode, WhitespaceNode, ERBContentNode, ERBEndNode, ERBElseNode, ERBIfNode, ERBBlockNode, ERBWhenNode, ERBCaseNode, ERBCaseMatchNode, ERBWhileNode, ERBUntilNode, ERBForNode, ERBRescueNode, ERBEnsureNode, ERBBeginNode, ERBUnlessNode, ERBYieldNode, ERBInNode } from "./nodes.js";
|
|
1
|
+
import { Node, ERBNode, DocumentNode, LiteralNode, HTMLOpenTagNode, HTMLConditionalOpenTagNode, HTMLCloseTagNode, HTMLOmittedCloseTagNode, HTMLVirtualCloseTagNode, HTMLElementNode, HTMLConditionalElementNode, HTMLAttributeValueNode, HTMLAttributeNameNode, HTMLAttributeNode, RubyLiteralNode, RubyHTMLAttributesSplatNode, ERBOpenTagNode, HTMLTextNode, HTMLCommentNode, HTMLDoctypeNode, XMLDeclarationNode, CDATANode, WhitespaceNode, ERBContentNode, ERBEndNode, ERBElseNode, ERBIfNode, ERBBlockNode, ERBWhenNode, ERBCaseNode, ERBCaseMatchNode, ERBWhileNode, ERBUntilNode, ERBForNode, ERBRescueNode, ERBEnsureNode, ERBBeginNode, ERBUnlessNode, ERBYieldNode, ERBInNode } from "./nodes.js";
|
|
2
2
|
/**
|
|
3
3
|
* Interface that enforces all node visit methods are implemented
|
|
4
4
|
* This ensures that any class implementing IVisitor must have a visit method for every node type
|
|
@@ -10,11 +10,18 @@ export interface IVisitor {
|
|
|
10
10
|
visitDocumentNode(node: DocumentNode): void;
|
|
11
11
|
visitLiteralNode(node: LiteralNode): void;
|
|
12
12
|
visitHTMLOpenTagNode(node: HTMLOpenTagNode): void;
|
|
13
|
+
visitHTMLConditionalOpenTagNode(node: HTMLConditionalOpenTagNode): void;
|
|
13
14
|
visitHTMLCloseTagNode(node: HTMLCloseTagNode): void;
|
|
15
|
+
visitHTMLOmittedCloseTagNode(node: HTMLOmittedCloseTagNode): void;
|
|
16
|
+
visitHTMLVirtualCloseTagNode(node: HTMLVirtualCloseTagNode): void;
|
|
14
17
|
visitHTMLElementNode(node: HTMLElementNode): void;
|
|
18
|
+
visitHTMLConditionalElementNode(node: HTMLConditionalElementNode): void;
|
|
15
19
|
visitHTMLAttributeValueNode(node: HTMLAttributeValueNode): void;
|
|
16
20
|
visitHTMLAttributeNameNode(node: HTMLAttributeNameNode): void;
|
|
17
21
|
visitHTMLAttributeNode(node: HTMLAttributeNode): void;
|
|
22
|
+
visitRubyLiteralNode(node: RubyLiteralNode): void;
|
|
23
|
+
visitRubyHTMLAttributesSplatNode(node: RubyHTMLAttributesSplatNode): void;
|
|
24
|
+
visitERBOpenTagNode(node: ERBOpenTagNode): void;
|
|
18
25
|
visitHTMLTextNode(node: HTMLTextNode): void;
|
|
19
26
|
visitHTMLCommentNode(node: HTMLCommentNode): void;
|
|
20
27
|
visitHTMLDoctypeNode(node: HTMLDoctypeNode): void;
|
|
@@ -50,11 +57,18 @@ export declare class Visitor implements IVisitor {
|
|
|
50
57
|
visitDocumentNode(node: DocumentNode): void;
|
|
51
58
|
visitLiteralNode(node: LiteralNode): void;
|
|
52
59
|
visitHTMLOpenTagNode(node: HTMLOpenTagNode): void;
|
|
60
|
+
visitHTMLConditionalOpenTagNode(node: HTMLConditionalOpenTagNode): void;
|
|
53
61
|
visitHTMLCloseTagNode(node: HTMLCloseTagNode): void;
|
|
62
|
+
visitHTMLOmittedCloseTagNode(node: HTMLOmittedCloseTagNode): void;
|
|
63
|
+
visitHTMLVirtualCloseTagNode(node: HTMLVirtualCloseTagNode): void;
|
|
54
64
|
visitHTMLElementNode(node: HTMLElementNode): void;
|
|
65
|
+
visitHTMLConditionalElementNode(node: HTMLConditionalElementNode): void;
|
|
55
66
|
visitHTMLAttributeValueNode(node: HTMLAttributeValueNode): void;
|
|
56
67
|
visitHTMLAttributeNameNode(node: HTMLAttributeNameNode): void;
|
|
57
68
|
visitHTMLAttributeNode(node: HTMLAttributeNode): void;
|
|
69
|
+
visitRubyLiteralNode(node: RubyLiteralNode): void;
|
|
70
|
+
visitRubyHTMLAttributesSplatNode(node: RubyHTMLAttributesSplatNode): void;
|
|
71
|
+
visitERBOpenTagNode(node: ERBOpenTagNode): void;
|
|
58
72
|
visitHTMLTextNode(node: HTMLTextNode): void;
|
|
59
73
|
visitHTMLCommentNode(node: HTMLCommentNode): void;
|
|
60
74
|
visitHTMLDoctypeNode(node: HTMLDoctypeNode): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herb-tools/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Core module exporting shared interfaces, AST node definitions, and common utilities for Herb",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://herb-tools.dev",
|
|
@@ -30,6 +30,9 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@ruby/prism": "^1.9.0"
|
|
35
|
+
},
|
|
33
36
|
"files": [
|
|
34
37
|
"package.json",
|
|
35
38
|
"README.md",
|