parent
1f5c7c791f
commit
8c45c4a856
113 changed files with 21295 additions and 21068 deletions
13
.eslintrc.cjs
Normal file
13
.eslintrc.cjs
Normal file
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
extends: ['plugin:@typescript-eslint/recommended', 'prettier'],
|
||||
plugins: ['@typescript-eslint', 'prettier'],
|
||||
rules: {
|
||||
'@typescript-eslint/camelcase': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-use-before-define': 'off',
|
||||
'@typescript-eslint/no-var-requires': 'off',
|
||||
'prettier/prettier': 'error',
|
||||
'prefer-const': 'off',
|
||||
},
|
||||
};
|
7
.prettierrc.json
Normal file
7
.prettierrc.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"printWidth": 180,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"tabWidth": 2,
|
||||
"trailingComma": "es5"
|
||||
}
|
917
package-lock.json
generated
917
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -17,7 +17,9 @@
|
|||
},
|
||||
"scripts": {
|
||||
"build": "tsc && npm run copy-js",
|
||||
"lint": "eslint 'src/**/*.{js,ts}'",
|
||||
"dev": "concurrently 'tsc --watch' 'npm run copy-js:watch'",
|
||||
"format": "prettier -w 'src/**/*.{js,ts}'",
|
||||
"copy-js": "copyfiles -u 1 src/*.js lib/",
|
||||
"copy-js:watch": "nodemon -w src --ext js --exec 'npm run copy-js'"
|
||||
},
|
||||
|
@ -45,12 +47,18 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/yargs-parser": "^20.2.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.18.0",
|
||||
"@typescript-eslint/parser": "^4.18.0",
|
||||
"concurrently": "^6.0.0",
|
||||
"copyfiles": "^2.4.1",
|
||||
"eslint": "^7.22.0",
|
||||
"eslint-config-prettier": "^8.1.0",
|
||||
"eslint-plugin-prettier": "^3.3.1",
|
||||
"estree-walker": "^3.0.0",
|
||||
"nodemon": "^2.0.7",
|
||||
"preact": "^10.5.12",
|
||||
"preact-render-to-string": "^5.1.14",
|
||||
"prettier": "^2.2.1",
|
||||
"typescript": "^4.2.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
export interface AstroConfigRaw {
|
||||
dist: string;
|
||||
projectRoot: string;
|
||||
|
|
26
src/@types/compiler/compile/Component.d.ts
vendored
26
src/@types/compiler/compile/Component.d.ts
vendored
|
@ -37,8 +37,8 @@ export default class Component {
|
|||
imports: ImportDeclaration[];
|
||||
hoistable_nodes: Set<Node>;
|
||||
node_for_declaration: Map<string, Node>;
|
||||
partly_hoisted: Array<(Node | Node[])>;
|
||||
fully_hoisted: Array<(Node | Node[])>;
|
||||
partly_hoisted: Array<Node | Node[]>;
|
||||
fully_hoisted: Array<Node | Node[]>;
|
||||
reactive_declarations: Array<{
|
||||
assignees: Set<string>;
|
||||
dependencies: Set<string>;
|
||||
|
@ -52,7 +52,9 @@ export default class Component {
|
|||
globals: Map<string, Identifier>;
|
||||
indirect_dependencies: Map<string, Set<string>>;
|
||||
file: string;
|
||||
locate: (c: number) => {
|
||||
locate: (
|
||||
c: number
|
||||
) => {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
|
@ -96,20 +98,26 @@ export default class Component {
|
|||
};
|
||||
get_unique_name(name: string, scope?: Scope): Identifier;
|
||||
get_unique_name_maker(): (name: string) => Identifier;
|
||||
error(pos: {
|
||||
error(
|
||||
pos: {
|
||||
start: number;
|
||||
end: number;
|
||||
}, e: {
|
||||
},
|
||||
e: {
|
||||
code: string;
|
||||
message: string;
|
||||
}): void;
|
||||
warn(pos: {
|
||||
}
|
||||
): void;
|
||||
warn(
|
||||
pos: {
|
||||
start: number;
|
||||
end: number;
|
||||
}, warning: {
|
||||
},
|
||||
warning: {
|
||||
code: string;
|
||||
message: string;
|
||||
}): void;
|
||||
}
|
||||
): void;
|
||||
extract_imports(node: any): void;
|
||||
extract_exports(node: any): any;
|
||||
extract_javascript(script: any): any;
|
||||
|
|
16
src/@types/compiler/compile/create_module.d.ts
vendored
16
src/@types/compiler/compile/create_module.d.ts
vendored
|
@ -4,11 +4,21 @@ interface Export {
|
|||
name: string;
|
||||
as: string;
|
||||
}
|
||||
export default function create_module(program: any, format: ModuleFormat, name: Identifier, banner: string, sveltePath: string, helpers: Array<{
|
||||
export default function create_module(
|
||||
program: any,
|
||||
format: ModuleFormat,
|
||||
name: Identifier,
|
||||
banner: string,
|
||||
sveltePath: string,
|
||||
helpers: Array<{
|
||||
name: string;
|
||||
alias: Identifier;
|
||||
}>, globals: Array<{
|
||||
}>,
|
||||
globals: Array<{
|
||||
name: string;
|
||||
alias: Identifier;
|
||||
}>, imports: ImportDeclaration[], module_exports: Export[]): void;
|
||||
}>,
|
||||
imports: ImportDeclaration[],
|
||||
module_exports: Export[]
|
||||
): void;
|
||||
export {};
|
||||
|
|
16
src/@types/compiler/compile/css/Stylesheet.d.ts
vendored
16
src/@types/compiler/compile/css/Stylesheet.d.ts
vendored
|
@ -47,7 +47,14 @@ export default class Stylesheet {
|
|||
children: Array<Rule | Atrule>;
|
||||
keyframes: Map<string, string>;
|
||||
nodes_with_css_class: Set<CssNode>;
|
||||
constructor({ source, ast, component_name, filename, dev, get_css_hash }: {
|
||||
constructor({
|
||||
source,
|
||||
ast,
|
||||
component_name,
|
||||
filename,
|
||||
dev,
|
||||
get_css_hash,
|
||||
}: {
|
||||
source: string;
|
||||
ast: Ast;
|
||||
filename: string | undefined;
|
||||
|
@ -57,9 +64,12 @@ export default class Stylesheet {
|
|||
});
|
||||
apply(node: Element): void;
|
||||
reify(): void;
|
||||
render(file: string, should_transform_selectors: boolean): {
|
||||
render(
|
||||
file: string,
|
||||
should_transform_selectors: boolean
|
||||
): {
|
||||
code: string;
|
||||
map: import("magic-string").SourceMap;
|
||||
map: import('magic-string').SourceMap;
|
||||
};
|
||||
validate(component: Component): void;
|
||||
warn_on_unused_selectors(component: Component): void;
|
||||
|
|
7
src/@types/compiler/compile/index.d.ts
vendored
7
src/@types/compiler/compile/index.d.ts
vendored
|
@ -1,8 +1,11 @@
|
|||
import { CompileOptions, Warning } from '../interfaces';
|
||||
export default function compile(source: string, options?: CompileOptions): {
|
||||
export default function compile(
|
||||
source: string,
|
||||
options?: CompileOptions
|
||||
): {
|
||||
js: any;
|
||||
css: any;
|
||||
ast: import("../interfaces").Ast;
|
||||
ast: import('../interfaces').Ast;
|
||||
warnings: Warning[];
|
||||
vars: {
|
||||
name: string;
|
||||
|
|
74
src/@types/compiler/compile/nodes/Attribute.d.ts
vendored
74
src/@types/compiler/compile/nodes/Attribute.d.ts
vendored
|
@ -21,7 +21,79 @@ export default class Attribute extends Node {
|
|||
dependencies: Set<string>;
|
||||
constructor(component: Component, parent: Node, scope: TemplateScope, info: TemplateNode);
|
||||
get_dependencies(): string[];
|
||||
get_value(block: any): import("estree").Identifier | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").Program | import("estree").FunctionDeclaration | import("estree").FunctionExpression | import("estree").ArrowFunctionExpression | import("estree").SwitchCase | import("estree").CatchClause | import("estree").VariableDeclarator | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").ClassDeclaration | import("estree").ThisExpression | import("estree").ArrayExpression | import("estree").ObjectExpression | import("estree").YieldExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").BinaryExpression | import("estree").AssignmentExpression | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").ConditionalExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").SequenceExpression | import("estree").TemplateLiteral | import("estree").TaggedTemplateExpression | import("estree").ClassExpression | import("estree").MetaProperty | import("estree").AwaitExpression | import("estree").ImportExpression | import("estree").ChainExpression | import("estree").Property | import("estree").Super | import("estree").TemplateElement | import("estree").SpreadElement | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").ClassBody | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier | {
|
||||
get_value(
|
||||
block: any
|
||||
):
|
||||
| import('estree').Identifier
|
||||
| import('estree').SimpleLiteral
|
||||
| import('estree').RegExpLiteral
|
||||
| import('estree').Program
|
||||
| import('estree').FunctionDeclaration
|
||||
| import('estree').FunctionExpression
|
||||
| import('estree').ArrowFunctionExpression
|
||||
| import('estree').SwitchCase
|
||||
| import('estree').CatchClause
|
||||
| import('estree').VariableDeclarator
|
||||
| import('estree').ExpressionStatement
|
||||
| import('estree').BlockStatement
|
||||
| import('estree').EmptyStatement
|
||||
| import('estree').DebuggerStatement
|
||||
| import('estree').WithStatement
|
||||
| import('estree').ReturnStatement
|
||||
| import('estree').LabeledStatement
|
||||
| import('estree').BreakStatement
|
||||
| import('estree').ContinueStatement
|
||||
| import('estree').IfStatement
|
||||
| import('estree').SwitchStatement
|
||||
| import('estree').ThrowStatement
|
||||
| import('estree').TryStatement
|
||||
| import('estree').WhileStatement
|
||||
| import('estree').DoWhileStatement
|
||||
| import('estree').ForStatement
|
||||
| import('estree').ForInStatement
|
||||
| import('estree').ForOfStatement
|
||||
| import('estree').VariableDeclaration
|
||||
| import('estree').ClassDeclaration
|
||||
| import('estree').ThisExpression
|
||||
| import('estree').ArrayExpression
|
||||
| import('estree').ObjectExpression
|
||||
| import('estree').YieldExpression
|
||||
| import('estree').UnaryExpression
|
||||
| import('estree').UpdateExpression
|
||||
| import('estree').BinaryExpression
|
||||
| import('estree').AssignmentExpression
|
||||
| import('estree').LogicalExpression
|
||||
| import('estree').MemberExpression
|
||||
| import('estree').ConditionalExpression
|
||||
| import('estree').SimpleCallExpression
|
||||
| import('estree').NewExpression
|
||||
| import('estree').SequenceExpression
|
||||
| import('estree').TemplateLiteral
|
||||
| import('estree').TaggedTemplateExpression
|
||||
| import('estree').ClassExpression
|
||||
| import('estree').MetaProperty
|
||||
| import('estree').AwaitExpression
|
||||
| import('estree').ImportExpression
|
||||
| import('estree').ChainExpression
|
||||
| import('estree').Property
|
||||
| import('estree').Super
|
||||
| import('estree').TemplateElement
|
||||
| import('estree').SpreadElement
|
||||
| import('estree').ObjectPattern
|
||||
| import('estree').ArrayPattern
|
||||
| import('estree').RestElement
|
||||
| import('estree').AssignmentPattern
|
||||
| import('estree').ClassBody
|
||||
| import('estree').MethodDefinition
|
||||
| import('estree').ImportDeclaration
|
||||
| import('estree').ExportNamedDeclaration
|
||||
| import('estree').ExportDefaultDeclaration
|
||||
| import('estree').ExportAllDeclaration
|
||||
| import('estree').ImportSpecifier
|
||||
| import('estree').ImportDefaultSpecifier
|
||||
| import('estree').ImportNamespaceSpecifier
|
||||
| import('estree').ExportSpecifier
|
||||
| {
|
||||
type: string;
|
||||
value: string;
|
||||
};
|
||||
|
|
|
@ -31,4 +31,37 @@ import ThenBlock from './ThenBlock';
|
|||
import Title from './Title';
|
||||
import Transition from './Transition';
|
||||
import Window from './Window';
|
||||
export declare type INode = Action | Animation | Attribute | AwaitBlock | Binding | Body | CatchBlock | Class | Comment | DebugTag | EachBlock | Element | ElseBlock | EventHandler | Fragment | Head | IfBlock | InlineComponent | KeyBlock | Let | MustacheTag | Options | PendingBlock | RawMustacheTag | Slot | SlotTemplate | DefaultSlotTemplate | Tag | Text | ThenBlock | Title | Transition | Window;
|
||||
export declare type INode =
|
||||
| Action
|
||||
| Animation
|
||||
| Attribute
|
||||
| AwaitBlock
|
||||
| Binding
|
||||
| Body
|
||||
| CatchBlock
|
||||
| Class
|
||||
| Comment
|
||||
| DebugTag
|
||||
| EachBlock
|
||||
| Element
|
||||
| ElseBlock
|
||||
| EventHandler
|
||||
| Fragment
|
||||
| Head
|
||||
| IfBlock
|
||||
| InlineComponent
|
||||
| KeyBlock
|
||||
| Let
|
||||
| MustacheTag
|
||||
| Options
|
||||
| PendingBlock
|
||||
| RawMustacheTag
|
||||
| Slot
|
||||
| SlotTemplate
|
||||
| DefaultSlotTemplate
|
||||
| Tag
|
||||
| Text
|
||||
| ThenBlock
|
||||
| Title
|
||||
| Transition
|
||||
| Window;
|
||||
|
|
|
@ -16,7 +16,7 @@ export default class Expression {
|
|||
template_scope: TemplateScope;
|
||||
scope: Scope;
|
||||
scope_map: WeakMap<Node, Scope>;
|
||||
declarations: Array<(Node | Node[])>;
|
||||
declarations: Array<Node | Node[]>;
|
||||
uses_context: boolean;
|
||||
manipulated: Node;
|
||||
constructor(component: Component, owner: Owner, template_scope: TemplateScope, info: Node, lazy?: boolean);
|
||||
|
|
|
@ -17,4 +17,27 @@ import Title from '../Title';
|
|||
import Window from '../Window';
|
||||
import { TemplateNode } from '../../../interfaces';
|
||||
export declare type Children = ReturnType<typeof map_children>;
|
||||
export default function map_children(component: any, parent: any, scope: any, children: TemplateNode[]): (AwaitBlock | Body | Comment | DebugTag | EachBlock | Element | Head | IfBlock | InlineComponent | KeyBlock | MustacheTag | Options | RawMustacheTag | SlotTemplate | Text | Title | Window)[];
|
||||
export default function map_children(
|
||||
component: any,
|
||||
parent: any,
|
||||
scope: any,
|
||||
children: TemplateNode[]
|
||||
): (
|
||||
| AwaitBlock
|
||||
| Body
|
||||
| Comment
|
||||
| DebugTag
|
||||
| EachBlock
|
||||
| Element
|
||||
| Head
|
||||
| IfBlock
|
||||
| InlineComponent
|
||||
| KeyBlock
|
||||
| MustacheTag
|
||||
| Options
|
||||
| RawMustacheTag
|
||||
| SlotTemplate
|
||||
| Text
|
||||
| Title
|
||||
| Window
|
||||
)[];
|
||||
|
|
|
@ -54,10 +54,13 @@ export default class Block {
|
|||
has_outro_method: boolean;
|
||||
outros: number;
|
||||
aliases: Map<string, Identifier>;
|
||||
variables: Map<string, {
|
||||
variables: Map<
|
||||
string,
|
||||
{
|
||||
id: Identifier;
|
||||
init?: Node;
|
||||
}>;
|
||||
}
|
||||
>;
|
||||
get_unique_name: (name: string) => Identifier;
|
||||
has_update_method: boolean;
|
||||
autofocus: string;
|
||||
|
|
|
@ -21,17 +21,22 @@ export default class Renderer {
|
|||
blocks: Array<Block | Node | Node[]>;
|
||||
readonly: Set<string>;
|
||||
meta_bindings: Array<Node | Node[]>;
|
||||
binding_groups: Map<string, {
|
||||
binding_groups: Map<
|
||||
string,
|
||||
{
|
||||
binding_group: (to_reference?: boolean) => Node;
|
||||
is_context: boolean;
|
||||
contexts: string[];
|
||||
index: number;
|
||||
keypath: string;
|
||||
}>;
|
||||
}
|
||||
>;
|
||||
block: Block;
|
||||
fragment: FragmentWrapper;
|
||||
file_var: Identifier;
|
||||
locate: (c: number) => {
|
||||
locate: (
|
||||
c: number
|
||||
) => {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import Component from '../Component';
|
||||
import { CompileOptions, CssResult } from '../../interfaces';
|
||||
import { Node } from 'estree';
|
||||
export default function dom(component: Component, options: CompileOptions): {
|
||||
export default function dom(
|
||||
component: Component,
|
||||
options: CompileOptions
|
||||
): {
|
||||
js: Node[];
|
||||
css: CssResult;
|
||||
};
|
||||
|
|
|
@ -21,7 +21,15 @@ declare class AwaitBlockBranch extends Wrapper {
|
|||
value_index: Literal;
|
||||
value_contexts: Context[];
|
||||
is_destructured: boolean;
|
||||
constructor(status: Status, renderer: Renderer, block: Block, parent: AwaitBlockWrapper, node: PendingBlock | ThenBlock | CatchBlock, strip_whitespace: boolean, next_sibling: Wrapper);
|
||||
constructor(
|
||||
status: Status,
|
||||
renderer: Renderer,
|
||||
block: Block,
|
||||
parent: AwaitBlockWrapper,
|
||||
node: PendingBlock | ThenBlock | CatchBlock,
|
||||
strip_whitespace: boolean,
|
||||
next_sibling: Wrapper
|
||||
);
|
||||
add_context(node: Node | null, contexts: Context[]): void;
|
||||
render(block: Block, parent_node: Identifier, parent_nodes: Identifier): void;
|
||||
render_destructure(): void;
|
||||
|
|
|
@ -34,7 +34,16 @@ export default class EachBlockWrapper extends Wrapper {
|
|||
var: Identifier;
|
||||
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: EachBlock, strip_whitespace: boolean, next_sibling: Wrapper);
|
||||
render(block: Block, parent_node: Identifier, parent_nodes: Identifier): void;
|
||||
render_keyed({ block, parent_node, parent_nodes, snippet, initial_anchor_node, initial_mount_node, update_anchor_node, update_mount_node }: {
|
||||
render_keyed({
|
||||
block,
|
||||
parent_node,
|
||||
parent_nodes,
|
||||
snippet,
|
||||
initial_anchor_node,
|
||||
initial_mount_node,
|
||||
update_anchor_node,
|
||||
update_mount_node,
|
||||
}: {
|
||||
block: Block;
|
||||
parent_node: Identifier;
|
||||
parent_nodes: Identifier;
|
||||
|
@ -44,7 +53,15 @@ export default class EachBlockWrapper extends Wrapper {
|
|||
update_anchor_node: Identifier;
|
||||
update_mount_node: Identifier;
|
||||
}): void;
|
||||
render_unkeyed({ block, parent_nodes, snippet, initial_anchor_node, initial_mount_node, update_anchor_node, update_mount_node }: {
|
||||
render_unkeyed({
|
||||
block,
|
||||
parent_nodes,
|
||||
snippet,
|
||||
initial_anchor_node,
|
||||
initial_mount_node,
|
||||
update_anchor_node,
|
||||
update_mount_node,
|
||||
}: {
|
||||
block: Block;
|
||||
parent_nodes: Identifier;
|
||||
snippet: Node;
|
||||
|
|
|
@ -26,17 +26,234 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
|
|||
get_dom_update_conditions(block: Block, dependency_condition: Node): Node;
|
||||
get_dependencies(): string[];
|
||||
get_metadata(): any;
|
||||
get_value(block: any): Identifier | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").Program | import("estree").FunctionDeclaration | import("estree").FunctionExpression | import("estree").ArrowFunctionExpression | import("estree").SwitchCase | import("estree").CatchClause | import("estree").VariableDeclarator | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").ClassDeclaration | import("estree").ThisExpression | import("estree").ArrayExpression | import("estree").ObjectExpression | import("estree").YieldExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").BinaryExpression | import("estree").AssignmentExpression | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").ConditionalExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").SequenceExpression | import("estree").TemplateLiteral | import("estree").TaggedTemplateExpression | import("estree").ClassExpression | import("estree").MetaProperty | import("estree").AwaitExpression | import("estree").ImportExpression | import("estree").ChainExpression | import("estree").Property | import("estree").Super | import("estree").TemplateElement | import("estree").SpreadElement | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").ClassBody | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier | {
|
||||
get_value(
|
||||
block: any
|
||||
):
|
||||
| Identifier
|
||||
| import('estree').SimpleLiteral
|
||||
| import('estree').RegExpLiteral
|
||||
| import('estree').Program
|
||||
| import('estree').FunctionDeclaration
|
||||
| import('estree').FunctionExpression
|
||||
| import('estree').ArrowFunctionExpression
|
||||
| import('estree').SwitchCase
|
||||
| import('estree').CatchClause
|
||||
| import('estree').VariableDeclarator
|
||||
| import('estree').ExpressionStatement
|
||||
| import('estree').BlockStatement
|
||||
| import('estree').EmptyStatement
|
||||
| import('estree').DebuggerStatement
|
||||
| import('estree').WithStatement
|
||||
| import('estree').ReturnStatement
|
||||
| import('estree').LabeledStatement
|
||||
| import('estree').BreakStatement
|
||||
| import('estree').ContinueStatement
|
||||
| import('estree').IfStatement
|
||||
| import('estree').SwitchStatement
|
||||
| import('estree').ThrowStatement
|
||||
| import('estree').TryStatement
|
||||
| import('estree').WhileStatement
|
||||
| import('estree').DoWhileStatement
|
||||
| import('estree').ForStatement
|
||||
| import('estree').ForInStatement
|
||||
| import('estree').ForOfStatement
|
||||
| import('estree').VariableDeclaration
|
||||
| import('estree').ClassDeclaration
|
||||
| import('estree').ThisExpression
|
||||
| import('estree').ArrayExpression
|
||||
| import('estree').ObjectExpression
|
||||
| import('estree').YieldExpression
|
||||
| import('estree').UnaryExpression
|
||||
| import('estree').UpdateExpression
|
||||
| import('estree').BinaryExpression
|
||||
| import('estree').AssignmentExpression
|
||||
| import('estree').LogicalExpression
|
||||
| import('estree').MemberExpression
|
||||
| import('estree').ConditionalExpression
|
||||
| import('estree').SimpleCallExpression
|
||||
| import('estree').NewExpression
|
||||
| import('estree').SequenceExpression
|
||||
| import('estree').TemplateLiteral
|
||||
| import('estree').TaggedTemplateExpression
|
||||
| import('estree').ClassExpression
|
||||
| import('estree').MetaProperty
|
||||
| import('estree').AwaitExpression
|
||||
| import('estree').ImportExpression
|
||||
| import('estree').ChainExpression
|
||||
| import('estree').Property
|
||||
| import('estree').Super
|
||||
| import('estree').TemplateElement
|
||||
| import('estree').SpreadElement
|
||||
| import('estree').ObjectPattern
|
||||
| import('estree').ArrayPattern
|
||||
| import('estree').RestElement
|
||||
| import('estree').AssignmentPattern
|
||||
| import('estree').ClassBody
|
||||
| import('estree').MethodDefinition
|
||||
| import('estree').ImportDeclaration
|
||||
| import('estree').ExportNamedDeclaration
|
||||
| import('estree').ExportDefaultDeclaration
|
||||
| import('estree').ExportAllDeclaration
|
||||
| import('estree').ImportSpecifier
|
||||
| import('estree').ImportDefaultSpecifier
|
||||
| import('estree').ImportNamespaceSpecifier
|
||||
| import('estree').ExportSpecifier
|
||||
| {
|
||||
type: string;
|
||||
value: string;
|
||||
};
|
||||
get_class_name_text(block: any): Identifier | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").Program | import("estree").FunctionDeclaration | import("estree").FunctionExpression | import("estree").ArrowFunctionExpression | import("estree").SwitchCase | import("estree").CatchClause | import("estree").VariableDeclarator | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").ClassDeclaration | import("estree").ThisExpression | import("estree").ArrayExpression | import("estree").ObjectExpression | import("estree").YieldExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").BinaryExpression | import("estree").AssignmentExpression | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").ConditionalExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").SequenceExpression | import("estree").TemplateLiteral | import("estree").TaggedTemplateExpression | import("estree").ClassExpression | import("estree").MetaProperty | import("estree").AwaitExpression | import("estree").ImportExpression | import("estree").ChainExpression | import("estree").Property | import("estree").Super | import("estree").TemplateElement | import("estree").SpreadElement | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").ClassBody | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier | {
|
||||
get_class_name_text(
|
||||
block: any
|
||||
):
|
||||
| Identifier
|
||||
| import('estree').SimpleLiteral
|
||||
| import('estree').RegExpLiteral
|
||||
| import('estree').Program
|
||||
| import('estree').FunctionDeclaration
|
||||
| import('estree').FunctionExpression
|
||||
| import('estree').ArrowFunctionExpression
|
||||
| import('estree').SwitchCase
|
||||
| import('estree').CatchClause
|
||||
| import('estree').VariableDeclarator
|
||||
| import('estree').ExpressionStatement
|
||||
| import('estree').BlockStatement
|
||||
| import('estree').EmptyStatement
|
||||
| import('estree').DebuggerStatement
|
||||
| import('estree').WithStatement
|
||||
| import('estree').ReturnStatement
|
||||
| import('estree').LabeledStatement
|
||||
| import('estree').BreakStatement
|
||||
| import('estree').ContinueStatement
|
||||
| import('estree').IfStatement
|
||||
| import('estree').SwitchStatement
|
||||
| import('estree').ThrowStatement
|
||||
| import('estree').TryStatement
|
||||
| import('estree').WhileStatement
|
||||
| import('estree').DoWhileStatement
|
||||
| import('estree').ForStatement
|
||||
| import('estree').ForInStatement
|
||||
| import('estree').ForOfStatement
|
||||
| import('estree').VariableDeclaration
|
||||
| import('estree').ClassDeclaration
|
||||
| import('estree').ThisExpression
|
||||
| import('estree').ArrayExpression
|
||||
| import('estree').ObjectExpression
|
||||
| import('estree').YieldExpression
|
||||
| import('estree').UnaryExpression
|
||||
| import('estree').UpdateExpression
|
||||
| import('estree').BinaryExpression
|
||||
| import('estree').AssignmentExpression
|
||||
| import('estree').LogicalExpression
|
||||
| import('estree').MemberExpression
|
||||
| import('estree').ConditionalExpression
|
||||
| import('estree').SimpleCallExpression
|
||||
| import('estree').NewExpression
|
||||
| import('estree').SequenceExpression
|
||||
| import('estree').TemplateLiteral
|
||||
| import('estree').TaggedTemplateExpression
|
||||
| import('estree').ClassExpression
|
||||
| import('estree').MetaProperty
|
||||
| import('estree').AwaitExpression
|
||||
| import('estree').ImportExpression
|
||||
| import('estree').ChainExpression
|
||||
| import('estree').Property
|
||||
| import('estree').Super
|
||||
| import('estree').TemplateElement
|
||||
| import('estree').SpreadElement
|
||||
| import('estree').ObjectPattern
|
||||
| import('estree').ArrayPattern
|
||||
| import('estree').RestElement
|
||||
| import('estree').AssignmentPattern
|
||||
| import('estree').ClassBody
|
||||
| import('estree').MethodDefinition
|
||||
| import('estree').ImportDeclaration
|
||||
| import('estree').ExportNamedDeclaration
|
||||
| import('estree').ExportDefaultDeclaration
|
||||
| import('estree').ExportAllDeclaration
|
||||
| import('estree').ImportSpecifier
|
||||
| import('estree').ImportDefaultSpecifier
|
||||
| import('estree').ImportNamespaceSpecifier
|
||||
| import('estree').ExportSpecifier
|
||||
| {
|
||||
type: string;
|
||||
value: string;
|
||||
};
|
||||
render_chunks(block: Block): (Identifier | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").Program | import("estree").FunctionDeclaration | import("estree").FunctionExpression | import("estree").ArrowFunctionExpression | import("estree").SwitchCase | import("estree").CatchClause | import("estree").VariableDeclarator | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").ClassDeclaration | import("estree").ThisExpression | import("estree").ArrayExpression | import("estree").ObjectExpression | import("estree").YieldExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").BinaryExpression | import("estree").AssignmentExpression | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").ConditionalExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").SequenceExpression | import("estree").TemplateLiteral | import("estree").TaggedTemplateExpression | import("estree").ClassExpression | import("estree").MetaProperty | import("estree").AwaitExpression | import("estree").ImportExpression | import("estree").ChainExpression | import("estree").Property | import("estree").Super | import("estree").TemplateElement | import("estree").SpreadElement | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").ClassBody | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier | {
|
||||
render_chunks(
|
||||
block: Block
|
||||
): (
|
||||
| Identifier
|
||||
| import('estree').SimpleLiteral
|
||||
| import('estree').RegExpLiteral
|
||||
| import('estree').Program
|
||||
| import('estree').FunctionDeclaration
|
||||
| import('estree').FunctionExpression
|
||||
| import('estree').ArrowFunctionExpression
|
||||
| import('estree').SwitchCase
|
||||
| import('estree').CatchClause
|
||||
| import('estree').VariableDeclarator
|
||||
| import('estree').ExpressionStatement
|
||||
| import('estree').BlockStatement
|
||||
| import('estree').EmptyStatement
|
||||
| import('estree').DebuggerStatement
|
||||
| import('estree').WithStatement
|
||||
| import('estree').ReturnStatement
|
||||
| import('estree').LabeledStatement
|
||||
| import('estree').BreakStatement
|
||||
| import('estree').ContinueStatement
|
||||
| import('estree').IfStatement
|
||||
| import('estree').SwitchStatement
|
||||
| import('estree').ThrowStatement
|
||||
| import('estree').TryStatement
|
||||
| import('estree').WhileStatement
|
||||
| import('estree').DoWhileStatement
|
||||
| import('estree').ForStatement
|
||||
| import('estree').ForInStatement
|
||||
| import('estree').ForOfStatement
|
||||
| import('estree').VariableDeclaration
|
||||
| import('estree').ClassDeclaration
|
||||
| import('estree').ThisExpression
|
||||
| import('estree').ArrayExpression
|
||||
| import('estree').ObjectExpression
|
||||
| import('estree').YieldExpression
|
||||
| import('estree').UnaryExpression
|
||||
| import('estree').UpdateExpression
|
||||
| import('estree').BinaryExpression
|
||||
| import('estree').AssignmentExpression
|
||||
| import('estree').LogicalExpression
|
||||
| import('estree').MemberExpression
|
||||
| import('estree').ConditionalExpression
|
||||
| import('estree').SimpleCallExpression
|
||||
| import('estree').NewExpression
|
||||
| import('estree').SequenceExpression
|
||||
| import('estree').TemplateLiteral
|
||||
| import('estree').TaggedTemplateExpression
|
||||
| import('estree').ClassExpression
|
||||
| import('estree').MetaProperty
|
||||
| import('estree').AwaitExpression
|
||||
| import('estree').ImportExpression
|
||||
| import('estree').ChainExpression
|
||||
| import('estree').Property
|
||||
| import('estree').Super
|
||||
| import('estree').TemplateElement
|
||||
| import('estree').SpreadElement
|
||||
| import('estree').ObjectPattern
|
||||
| import('estree').ArrayPattern
|
||||
| import('estree').RestElement
|
||||
| import('estree').AssignmentPattern
|
||||
| import('estree').ClassBody
|
||||
| import('estree').MethodDefinition
|
||||
| import('estree').ImportDeclaration
|
||||
| import('estree').ExportNamedDeclaration
|
||||
| import('estree').ExportDefaultDeclaration
|
||||
| import('estree').ExportAllDeclaration
|
||||
| import('estree').ImportSpecifier
|
||||
| import('estree').ImportDefaultSpecifier
|
||||
| import('estree').ImportNamespaceSpecifier
|
||||
| import('estree').ExportSpecifier
|
||||
| {
|
||||
type: string;
|
||||
value: string;
|
||||
})[];
|
||||
}
|
||||
)[];
|
||||
stringify(): string;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ export default class BindingWrapper {
|
|||
object: string;
|
||||
handler: {
|
||||
uses_context: boolean;
|
||||
mutation: (Node | Node[]);
|
||||
mutation: Node | Node[];
|
||||
contextual_dependencies: Set<string>;
|
||||
lhs?: Node;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
import { BaseAttributeWrapper } from './Attribute';
|
||||
export default class SpreadAttributeWrapper extends BaseAttributeWrapper {
|
||||
}
|
||||
export default class SpreadAttributeWrapper extends BaseAttributeWrapper {}
|
||||
|
|
|
@ -26,8 +26,8 @@ export default class ElementWrapper extends Wrapper {
|
|||
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: Element, strip_whitespace: boolean, next_sibling: Wrapper);
|
||||
render(block: Block, parent_node: Identifier, parent_nodes: Identifier): void;
|
||||
can_use_textcontent(): boolean;
|
||||
get_render_statement(block: Block): import("estree").Expression;
|
||||
get_claim_statement(nodes: Identifier): import("estree").Expression;
|
||||
get_render_statement(block: Block): import('estree').Expression;
|
||||
get_claim_statement(nodes: Identifier): import('estree').Expression;
|
||||
add_directives_in_order(block: Block): void;
|
||||
add_bindings(block: Block, binding_group: BindingGroup): void;
|
||||
add_this_binding(block: Block, this_binding: Binding): void;
|
||||
|
|
|
@ -23,32 +23,70 @@ export default class IfBlockWrapper extends Wrapper {
|
|||
var: Identifier;
|
||||
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: EachBlock, strip_whitespace: boolean, next_sibling: Wrapper);
|
||||
render(block: Block, parent_node: Identifier, parent_nodes: Identifier): void;
|
||||
render_compound(block: Block, parent_node: Identifier, _parent_nodes: Identifier, dynamic: any, { name, anchor, has_else, if_exists_condition, has_transitions }: {
|
||||
render_compound(
|
||||
block: Block,
|
||||
parent_node: Identifier,
|
||||
_parent_nodes: Identifier,
|
||||
dynamic: any,
|
||||
{
|
||||
name,
|
||||
anchor,
|
||||
has_else,
|
||||
if_exists_condition,
|
||||
has_transitions,
|
||||
}: {
|
||||
name: any;
|
||||
anchor: any;
|
||||
has_else: any;
|
||||
if_exists_condition: any;
|
||||
has_transitions: any;
|
||||
}, detaching: any): void;
|
||||
render_compound_with_outros(block: Block, parent_node: Identifier, _parent_nodes: Identifier, dynamic: any, { name, anchor, has_else, has_transitions, if_exists_condition }: {
|
||||
},
|
||||
detaching: any
|
||||
): void;
|
||||
render_compound_with_outros(
|
||||
block: Block,
|
||||
parent_node: Identifier,
|
||||
_parent_nodes: Identifier,
|
||||
dynamic: any,
|
||||
{
|
||||
name,
|
||||
anchor,
|
||||
has_else,
|
||||
has_transitions,
|
||||
if_exists_condition,
|
||||
}: {
|
||||
name: any;
|
||||
anchor: any;
|
||||
has_else: any;
|
||||
has_transitions: any;
|
||||
if_exists_condition: any;
|
||||
}, detaching: any): void;
|
||||
render_simple(block: Block, parent_node: Identifier, _parent_nodes: Identifier, dynamic: any, { name, anchor, if_exists_condition, has_transitions }: {
|
||||
},
|
||||
detaching: any
|
||||
): void;
|
||||
render_simple(
|
||||
block: Block,
|
||||
parent_node: Identifier,
|
||||
_parent_nodes: Identifier,
|
||||
dynamic: any,
|
||||
{
|
||||
name,
|
||||
anchor,
|
||||
if_exists_condition,
|
||||
has_transitions,
|
||||
}: {
|
||||
name: any;
|
||||
anchor: any;
|
||||
if_exists_condition: any;
|
||||
has_transitions: any;
|
||||
}, detaching: any): void;
|
||||
},
|
||||
detaching: any
|
||||
): void;
|
||||
get_initial_dirty_bit(): {
|
||||
readonly type: "ArrayExpression" | "UnaryExpression";
|
||||
readonly type: 'ArrayExpression' | 'UnaryExpression';
|
||||
elements: UnaryExpression[];
|
||||
operator: import("estree").UnaryOperator;
|
||||
operator: import('estree').UnaryOperator;
|
||||
prefix: true;
|
||||
argument: import("estree").Expression;
|
||||
argument: import('estree').Expression;
|
||||
};
|
||||
}
|
||||
export {};
|
||||
|
|
|
@ -8,7 +8,79 @@ export default class Tag extends Wrapper {
|
|||
node: MustacheTag | RawMustacheTag;
|
||||
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: MustacheTag | RawMustacheTag);
|
||||
is_dependencies_static(): boolean;
|
||||
rename_this_method(block: Block, update: ((value: Node) => (Node | Node[]))): {
|
||||
init: import("estree").Identifier | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").Program | import("estree").FunctionDeclaration | import("estree").FunctionExpression | import("estree").ArrowFunctionExpression | import("estree").SwitchCase | import("estree").CatchClause | import("estree").VariableDeclarator | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").ClassDeclaration | import("estree").ThisExpression | import("estree").ArrayExpression | import("estree").ObjectExpression | import("estree").YieldExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").BinaryExpression | import("estree").AssignmentExpression | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").ConditionalExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").SequenceExpression | import("estree").TemplateLiteral | import("estree").TaggedTemplateExpression | import("estree").ClassExpression | import("estree").MetaProperty | import("estree").AwaitExpression | import("estree").ImportExpression | import("estree").ChainExpression | import("estree").Property | import("estree").Super | import("estree").TemplateElement | import("estree").SpreadElement | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").ClassBody | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier;
|
||||
rename_this_method(
|
||||
block: Block,
|
||||
update: (value: Node) => Node | Node[]
|
||||
): {
|
||||
init:
|
||||
| import('estree').Identifier
|
||||
| import('estree').SimpleLiteral
|
||||
| import('estree').RegExpLiteral
|
||||
| import('estree').Program
|
||||
| import('estree').FunctionDeclaration
|
||||
| import('estree').FunctionExpression
|
||||
| import('estree').ArrowFunctionExpression
|
||||
| import('estree').SwitchCase
|
||||
| import('estree').CatchClause
|
||||
| import('estree').VariableDeclarator
|
||||
| import('estree').ExpressionStatement
|
||||
| import('estree').BlockStatement
|
||||
| import('estree').EmptyStatement
|
||||
| import('estree').DebuggerStatement
|
||||
| import('estree').WithStatement
|
||||
| import('estree').ReturnStatement
|
||||
| import('estree').LabeledStatement
|
||||
| import('estree').BreakStatement
|
||||
| import('estree').ContinueStatement
|
||||
| import('estree').IfStatement
|
||||
| import('estree').SwitchStatement
|
||||
| import('estree').ThrowStatement
|
||||
| import('estree').TryStatement
|
||||
| import('estree').WhileStatement
|
||||
| import('estree').DoWhileStatement
|
||||
| import('estree').ForStatement
|
||||
| import('estree').ForInStatement
|
||||
| import('estree').ForOfStatement
|
||||
| import('estree').VariableDeclaration
|
||||
| import('estree').ClassDeclaration
|
||||
| import('estree').ThisExpression
|
||||
| import('estree').ArrayExpression
|
||||
| import('estree').ObjectExpression
|
||||
| import('estree').YieldExpression
|
||||
| import('estree').UnaryExpression
|
||||
| import('estree').UpdateExpression
|
||||
| import('estree').BinaryExpression
|
||||
| import('estree').AssignmentExpression
|
||||
| import('estree').LogicalExpression
|
||||
| import('estree').MemberExpression
|
||||
| import('estree').ConditionalExpression
|
||||
| import('estree').SimpleCallExpression
|
||||
| import('estree').NewExpression
|
||||
| import('estree').SequenceExpression
|
||||
| import('estree').TemplateLiteral
|
||||
| import('estree').TaggedTemplateExpression
|
||||
| import('estree').ClassExpression
|
||||
| import('estree').MetaProperty
|
||||
| import('estree').AwaitExpression
|
||||
| import('estree').ImportExpression
|
||||
| import('estree').ChainExpression
|
||||
| import('estree').Property
|
||||
| import('estree').Super
|
||||
| import('estree').TemplateElement
|
||||
| import('estree').SpreadElement
|
||||
| import('estree').ObjectPattern
|
||||
| import('estree').ArrayPattern
|
||||
| import('estree').RestElement
|
||||
| import('estree').AssignmentPattern
|
||||
| import('estree').ClassBody
|
||||
| import('estree').MethodDefinition
|
||||
| import('estree').ImportDeclaration
|
||||
| import('estree').ExportNamedDeclaration
|
||||
| import('estree').ExportDefaultDeclaration
|
||||
| import('estree').ExportAllDeclaration
|
||||
| import('estree').ImportSpecifier
|
||||
| import('estree').ImportDefaultSpecifier
|
||||
| import('estree').ImportNamespaceSpecifier
|
||||
| import('estree').ExportSpecifier;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@ import Component from '../../../Component';
|
|||
import Block from '../../Block';
|
||||
import BindingWrapper from '../Element/Binding';
|
||||
import { Identifier } from 'estree';
|
||||
export default function bind_this(component: Component, block: Block, binding: BindingWrapper, variable: Identifier): import("estree").Node[];
|
||||
export default function bind_this(component: Component, block: Block, binding: BindingWrapper, variable: Identifier): import('estree').Node[];
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
import Let from '../../../nodes/Let';
|
||||
import Block from '../../Block';
|
||||
import TemplateScope from '../../../nodes/shared/TemplateScope';
|
||||
export declare function get_slot_definition(block: Block, scope: TemplateScope, lets: Let[]): {
|
||||
export declare function get_slot_definition(
|
||||
block: Block,
|
||||
scope: TemplateScope,
|
||||
lets: Let[]
|
||||
):
|
||||
| {
|
||||
block: Block;
|
||||
scope: TemplateScope;
|
||||
get_context?: undefined;
|
||||
get_changes?: undefined;
|
||||
} | {
|
||||
}
|
||||
| {
|
||||
block: Block;
|
||||
scope: TemplateScope;
|
||||
get_context: import("estree").Expression;
|
||||
get_changes: import("estree").Expression;
|
||||
get_context: import('estree').Expression;
|
||||
get_changes: import('estree').Expression;
|
||||
};
|
||||
|
|
|
@ -2,7 +2,9 @@ import { AppendTarget, CompileOptions } from '../../interfaces';
|
|||
import { INode } from '../nodes/interfaces';
|
||||
import { Expression, TemplateLiteral, Identifier } from 'estree';
|
||||
export interface RenderOptions extends CompileOptions {
|
||||
locate: (c: number) => {
|
||||
locate: (
|
||||
c: number
|
||||
) => {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
|
@ -22,9 +24,7 @@ export default class Renderer {
|
|||
};
|
||||
literal: TemplateLiteral;
|
||||
targets: AppendTarget[];
|
||||
constructor({ name }: {
|
||||
name: any;
|
||||
});
|
||||
constructor({ name }: { name: any });
|
||||
add_string(str: string): void;
|
||||
add_expression(node: Expression): void;
|
||||
push(): void;
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import Renderer, { RenderOptions } from '../Renderer';
|
||||
import Slot from '../../nodes/Slot';
|
||||
export default function (node: Slot, renderer: Renderer, options: RenderOptions & {
|
||||
export default function (
|
||||
node: Slot,
|
||||
renderer: Renderer,
|
||||
options: RenderOptions & {
|
||||
slot_scopes: Map<any, any>;
|
||||
}): void;
|
||||
}
|
||||
): void;
|
||||
|
|
|
@ -2,6 +2,10 @@ import Renderer, { RenderOptions } from '../Renderer';
|
|||
import SlotTemplate from '../../nodes/SlotTemplate';
|
||||
import InlineComponent from '../../nodes/InlineComponent';
|
||||
import Element from '../../nodes/Element';
|
||||
export default function (node: SlotTemplate | Element | InlineComponent, renderer: Renderer, options: RenderOptions & {
|
||||
export default function (
|
||||
node: SlotTemplate | Element | InlineComponent,
|
||||
renderer: Renderer,
|
||||
options: RenderOptions & {
|
||||
slot_scopes: Map<any, any>;
|
||||
}): void;
|
||||
}
|
||||
): void;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import Component from '../Component';
|
||||
import { CompileOptions, CssResult } from '../../interfaces';
|
||||
import { Node } from 'estree';
|
||||
export default function ssr(component: Component, options: CompileOptions): {
|
||||
export default function ssr(
|
||||
component: Component,
|
||||
options: CompileOptions
|
||||
): {
|
||||
js: Node[];
|
||||
css: CssResult;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { Node } from 'estree';
|
||||
export default function flatten_reference(node: Node): {
|
||||
export default function flatten_reference(
|
||||
node: Node
|
||||
): {
|
||||
name: string;
|
||||
nodes: any[];
|
||||
parts: any[];
|
||||
|
|
|
@ -1,9 +1,85 @@
|
|||
import Attribute from '../nodes/Attribute';
|
||||
import Block from '../render_dom/Block';
|
||||
export default function get_slot_data(values: Map<string, Attribute>, block?: Block): {
|
||||
export default function get_slot_data(
|
||||
values: Map<string, Attribute>,
|
||||
block?: Block
|
||||
): {
|
||||
type: string;
|
||||
properties: (import("estree").Property | import("estree").SpreadElement | {
|
||||
properties: (
|
||||
| import('estree').Property
|
||||
| import('estree').SpreadElement
|
||||
| {
|
||||
type: string;
|
||||
argument: import("estree").Identifier | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").Program | import("estree").FunctionDeclaration | import("estree").FunctionExpression | import("estree").ArrowFunctionExpression | import("estree").SwitchCase | import("estree").CatchClause | import("estree").VariableDeclarator | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").ClassDeclaration | import("estree").ThisExpression | import("estree").ArrayExpression | import("estree").ObjectExpression | import("estree").YieldExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").BinaryExpression | import("estree").AssignmentExpression | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").ConditionalExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").SequenceExpression | import("estree").TemplateLiteral | import("estree").TaggedTemplateExpression | import("estree").ClassExpression | import("estree").MetaProperty | import("estree").AwaitExpression | import("estree").ImportExpression | import("estree").ChainExpression | import("estree").Property | import("estree").Super | import("estree").TemplateElement | import("estree").SpreadElement | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").ClassBody | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier;
|
||||
})[];
|
||||
argument:
|
||||
| import('estree').Identifier
|
||||
| import('estree').SimpleLiteral
|
||||
| import('estree').RegExpLiteral
|
||||
| import('estree').Program
|
||||
| import('estree').FunctionDeclaration
|
||||
| import('estree').FunctionExpression
|
||||
| import('estree').ArrowFunctionExpression
|
||||
| import('estree').SwitchCase
|
||||
| import('estree').CatchClause
|
||||
| import('estree').VariableDeclarator
|
||||
| import('estree').ExpressionStatement
|
||||
| import('estree').BlockStatement
|
||||
| import('estree').EmptyStatement
|
||||
| import('estree').DebuggerStatement
|
||||
| import('estree').WithStatement
|
||||
| import('estree').ReturnStatement
|
||||
| import('estree').LabeledStatement
|
||||
| import('estree').BreakStatement
|
||||
| import('estree').ContinueStatement
|
||||
| import('estree').IfStatement
|
||||
| import('estree').SwitchStatement
|
||||
| import('estree').ThrowStatement
|
||||
| import('estree').TryStatement
|
||||
| import('estree').WhileStatement
|
||||
| import('estree').DoWhileStatement
|
||||
| import('estree').ForStatement
|
||||
| import('estree').ForInStatement
|
||||
| import('estree').ForOfStatement
|
||||
| import('estree').VariableDeclaration
|
||||
| import('estree').ClassDeclaration
|
||||
| import('estree').ThisExpression
|
||||
| import('estree').ArrayExpression
|
||||
| import('estree').ObjectExpression
|
||||
| import('estree').YieldExpression
|
||||
| import('estree').UnaryExpression
|
||||
| import('estree').UpdateExpression
|
||||
| import('estree').BinaryExpression
|
||||
| import('estree').AssignmentExpression
|
||||
| import('estree').LogicalExpression
|
||||
| import('estree').MemberExpression
|
||||
| import('estree').ConditionalExpression
|
||||
| import('estree').SimpleCallExpression
|
||||
| import('estree').NewExpression
|
||||
| import('estree').SequenceExpression
|
||||
| import('estree').TemplateLiteral
|
||||
| import('estree').TaggedTemplateExpression
|
||||
| import('estree').ClassExpression
|
||||
| import('estree').MetaProperty
|
||||
| import('estree').AwaitExpression
|
||||
| import('estree').ImportExpression
|
||||
| import('estree').ChainExpression
|
||||
| import('estree').Property
|
||||
| import('estree').Super
|
||||
| import('estree').TemplateElement
|
||||
| import('estree').SpreadElement
|
||||
| import('estree').ObjectPattern
|
||||
| import('estree').ArrayPattern
|
||||
| import('estree').RestElement
|
||||
| import('estree').AssignmentPattern
|
||||
| import('estree').ClassBody
|
||||
| import('estree').MethodDefinition
|
||||
| import('estree').ImportDeclaration
|
||||
| import('estree').ExportNamedDeclaration
|
||||
| import('estree').ExportDefaultDeclaration
|
||||
| import('estree').ExportAllDeclaration
|
||||
| import('estree').ImportSpecifier
|
||||
| import('estree').ImportDefaultSpecifier
|
||||
| import('estree').ImportNamespaceSpecifier
|
||||
| import('estree').ExportSpecifier;
|
||||
}
|
||||
)[];
|
||||
};
|
||||
|
|
|
@ -1,2 +1,74 @@
|
|||
import { Node } from 'estree';
|
||||
export default function replace_object(node: Node, replacement: Node): import("estree").Identifier | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").Program | import("estree").FunctionDeclaration | import("estree").FunctionExpression | import("estree").ArrowFunctionExpression | import("estree").SwitchCase | import("estree").CatchClause | import("estree").VariableDeclarator | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").ClassDeclaration | import("estree").ThisExpression | import("estree").ArrayExpression | import("estree").ObjectExpression | import("estree").YieldExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").BinaryExpression | import("estree").AssignmentExpression | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").ConditionalExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").SequenceExpression | import("estree").TemplateLiteral | import("estree").TaggedTemplateExpression | import("estree").ClassExpression | import("estree").MetaProperty | import("estree").AwaitExpression | import("estree").ImportExpression | import("estree").ChainExpression | import("estree").Property | import("estree").Super | import("estree").TemplateElement | import("estree").SpreadElement | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").ClassBody | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier;
|
||||
export default function replace_object(
|
||||
node: Node,
|
||||
replacement: Node
|
||||
):
|
||||
| import('estree').Identifier
|
||||
| import('estree').SimpleLiteral
|
||||
| import('estree').RegExpLiteral
|
||||
| import('estree').Program
|
||||
| import('estree').FunctionDeclaration
|
||||
| import('estree').FunctionExpression
|
||||
| import('estree').ArrowFunctionExpression
|
||||
| import('estree').SwitchCase
|
||||
| import('estree').CatchClause
|
||||
| import('estree').VariableDeclarator
|
||||
| import('estree').ExpressionStatement
|
||||
| import('estree').BlockStatement
|
||||
| import('estree').EmptyStatement
|
||||
| import('estree').DebuggerStatement
|
||||
| import('estree').WithStatement
|
||||
| import('estree').ReturnStatement
|
||||
| import('estree').LabeledStatement
|
||||
| import('estree').BreakStatement
|
||||
| import('estree').ContinueStatement
|
||||
| import('estree').IfStatement
|
||||
| import('estree').SwitchStatement
|
||||
| import('estree').ThrowStatement
|
||||
| import('estree').TryStatement
|
||||
| import('estree').WhileStatement
|
||||
| import('estree').DoWhileStatement
|
||||
| import('estree').ForStatement
|
||||
| import('estree').ForInStatement
|
||||
| import('estree').ForOfStatement
|
||||
| import('estree').VariableDeclaration
|
||||
| import('estree').ClassDeclaration
|
||||
| import('estree').ThisExpression
|
||||
| import('estree').ArrayExpression
|
||||
| import('estree').ObjectExpression
|
||||
| import('estree').YieldExpression
|
||||
| import('estree').UnaryExpression
|
||||
| import('estree').UpdateExpression
|
||||
| import('estree').BinaryExpression
|
||||
| import('estree').AssignmentExpression
|
||||
| import('estree').LogicalExpression
|
||||
| import('estree').MemberExpression
|
||||
| import('estree').ConditionalExpression
|
||||
| import('estree').SimpleCallExpression
|
||||
| import('estree').NewExpression
|
||||
| import('estree').SequenceExpression
|
||||
| import('estree').TemplateLiteral
|
||||
| import('estree').TaggedTemplateExpression
|
||||
| import('estree').ClassExpression
|
||||
| import('estree').MetaProperty
|
||||
| import('estree').AwaitExpression
|
||||
| import('estree').ImportExpression
|
||||
| import('estree').ChainExpression
|
||||
| import('estree').Property
|
||||
| import('estree').Super
|
||||
| import('estree').TemplateElement
|
||||
| import('estree').SpreadElement
|
||||
| import('estree').ObjectPattern
|
||||
| import('estree').ArrayPattern
|
||||
| import('estree').RestElement
|
||||
| import('estree').AssignmentPattern
|
||||
| import('estree').ClassBody
|
||||
| import('estree').MethodDefinition
|
||||
| import('estree').ImportDeclaration
|
||||
| import('estree').ExportNamedDeclaration
|
||||
| import('estree').ExportDefaultDeclaration
|
||||
| import('estree').ExportAllDeclaration
|
||||
| import('estree').ImportSpecifier
|
||||
| import('estree').ImportDefaultSpecifier
|
||||
| import('estree').ImportNamespaceSpecifier
|
||||
| import('estree').ExportSpecifier;
|
||||
|
|
4
src/@types/compiler/compile/utils/scope.d.ts
vendored
4
src/@types/compiler/compile/utils/scope.d.ts
vendored
|
@ -1,6 +1,8 @@
|
|||
import { Node } from 'estree';
|
||||
import { Scope, extract_names, extract_identifiers } from 'periscopic';
|
||||
export declare function create_scopes(expression: Node): {
|
||||
export declare function create_scopes(
|
||||
expression: Node
|
||||
): {
|
||||
map: WeakMap<Node, Scope>;
|
||||
scope: Scope;
|
||||
globals: Map<string, Node>;
|
||||
|
|
13
src/@types/compiler/compile/utils/stringify.d.ts
vendored
13
src/@types/compiler/compile/utils/stringify.d.ts
vendored
|
@ -1,9 +1,16 @@
|
|||
export declare function string_literal(data: string): {
|
||||
export declare function string_literal(
|
||||
data: string
|
||||
): {
|
||||
type: string;
|
||||
value: string;
|
||||
};
|
||||
export declare function escape(data: string, { only_escape_at_symbol }?: {
|
||||
export declare function escape(
|
||||
data: string,
|
||||
{
|
||||
only_escape_at_symbol,
|
||||
}?: {
|
||||
only_escape_at_symbol?: boolean;
|
||||
}): string;
|
||||
}
|
||||
): string;
|
||||
export declare function escape_html(html: any): string;
|
||||
export declare function escape_template(str: any): any;
|
||||
|
|
2
src/@types/compiler/index.d.ts
vendored
2
src/@types/compiler/index.d.ts
vendored
|
@ -2,4 +2,4 @@ export { default as compile } from './compile/index';
|
|||
export { default as parse } from './parse/index';
|
||||
export { default as preprocess } from './preprocess/index';
|
||||
export { walk } from 'estree-walker';
|
||||
export declare const VERSION = "__VERSION__";
|
||||
export declare const VERSION = '__VERSION__';
|
||||
|
|
7
src/@types/compiler/interfaces.d.ts
vendored
7
src/@types/compiler/interfaces.d.ts
vendored
|
@ -82,12 +82,7 @@ export interface Warning {
|
|||
toString: () => string;
|
||||
}
|
||||
export declare type ModuleFormat = 'esm' | 'cjs';
|
||||
export declare type CssHashGetter = (args: {
|
||||
name: string;
|
||||
filename: string | undefined;
|
||||
css: string;
|
||||
hash: (input: string) => string;
|
||||
}) => string;
|
||||
export declare type CssHashGetter = (args: { name: string; filename: string | undefined; css: string; hash: (input: string) => string }) => string;
|
||||
export interface CompileOptions {
|
||||
format?: ModuleFormat;
|
||||
name?: string;
|
||||
|
|
10
src/@types/compiler/parse/index.d.ts
vendored
10
src/@types/compiler/parse/index.d.ts
vendored
|
@ -18,10 +18,16 @@ export declare class Parser {
|
|||
constructor(template: string, options: ParserOptions);
|
||||
current(): TemplateNode;
|
||||
acorn_error(err: any): void;
|
||||
error({ code, message }: {
|
||||
error(
|
||||
{
|
||||
code,
|
||||
message,
|
||||
}: {
|
||||
code: string;
|
||||
message: string;
|
||||
}, index?: number): void;
|
||||
},
|
||||
index?: number
|
||||
): void;
|
||||
eat(str: string, required?: boolean, message?: string): boolean;
|
||||
match(str: string): boolean;
|
||||
match_regex(pattern: RegExp): string;
|
||||
|
|
4
src/@types/compiler/parse/read/context.d.ts
vendored
4
src/@types/compiler/parse/read/context.d.ts
vendored
|
@ -1,6 +1,8 @@
|
|||
import { Parser } from '../index';
|
||||
import { Pattern } from 'estree';
|
||||
export default function read_context(parser: Parser): Pattern & {
|
||||
export default function read_context(
|
||||
parser: Parser
|
||||
): Pattern & {
|
||||
start: number;
|
||||
end: number;
|
||||
};
|
||||
|
|
8
src/@types/compiler/preprocess/index.d.ts
vendored
8
src/@types/compiler/preprocess/index.d.ts
vendored
|
@ -1,4 +1,8 @@
|
|||
import { PreprocessorGroup, Processed } from './types';
|
||||
export default function preprocess(source: string, preprocessor: PreprocessorGroup | PreprocessorGroup[], options?: {
|
||||
export default function preprocess(
|
||||
source: string,
|
||||
preprocessor: PreprocessorGroup | PreprocessorGroup[],
|
||||
options?: {
|
||||
filename?: string;
|
||||
}): Promise<Processed>;
|
||||
}
|
||||
): Promise<Processed>;
|
||||
|
|
11
src/@types/compiler/preprocess/types.d.ts
vendored
11
src/@types/compiler/preprocess/types.d.ts
vendored
|
@ -11,15 +11,8 @@ export interface Processed {
|
|||
dependencies?: string[];
|
||||
toString?: () => string;
|
||||
}
|
||||
export declare type MarkupPreprocessor = (options: {
|
||||
content: string;
|
||||
filename: string;
|
||||
}) => Processed | Promise<Processed>;
|
||||
export declare type Preprocessor = (options: {
|
||||
content: string;
|
||||
attributes: Record<string, string | boolean>;
|
||||
filename?: string;
|
||||
}) => Processed | Promise<Processed>;
|
||||
export declare type MarkupPreprocessor = (options: { content: string; filename: string }) => Processed | Promise<Processed>;
|
||||
export declare type Preprocessor = (options: { content: string; attributes: Record<string, string | boolean>; filename?: string }) => Processed | Promise<Processed>;
|
||||
export interface PreprocessorGroup {
|
||||
markup?: MarkupPreprocessor;
|
||||
style?: Preprocessor;
|
||||
|
|
7
src/@types/compiler/utils/error.d.ts
vendored
7
src/@types/compiler/utils/error.d.ts
vendored
|
@ -1,8 +1,11 @@
|
|||
export default function error(message: string, props: {
|
||||
export default function error(
|
||||
message: string,
|
||||
props: {
|
||||
name: string;
|
||||
code: string;
|
||||
source: string;
|
||||
filename: string;
|
||||
start: number;
|
||||
end?: number;
|
||||
}): never;
|
||||
}
|
||||
): never;
|
||||
|
|
6
src/@types/compiler/utils/link.d.ts
vendored
6
src/@types/compiler/utils/link.d.ts
vendored
|
@ -1,4 +1,6 @@
|
|||
export declare function link<T extends {
|
||||
export declare function link<
|
||||
T extends {
|
||||
next?: T;
|
||||
prev?: T;
|
||||
}>(next: T, prev: T): void;
|
||||
}
|
||||
>(next: T, prev: T): void;
|
||||
|
|
14
src/@types/compiler/utils/namespaces.d.ts
vendored
14
src/@types/compiler/utils/namespaces.d.ts
vendored
|
@ -1,9 +1,9 @@
|
|||
export declare const foreign = "https://svelte.dev/docs#svelte_options";
|
||||
export declare const html = "http://www.w3.org/1999/xhtml";
|
||||
export declare const mathml = "http://www.w3.org/1998/Math/MathML";
|
||||
export declare const svg = "http://www.w3.org/2000/svg";
|
||||
export declare const xlink = "http://www.w3.org/1999/xlink";
|
||||
export declare const xml = "http://www.w3.org/XML/1998/namespace";
|
||||
export declare const xmlns = "http://www.w3.org/2000/xmlns";
|
||||
export declare const foreign = 'https://svelte.dev/docs#svelte_options';
|
||||
export declare const html = 'http://www.w3.org/1999/xhtml';
|
||||
export declare const mathml = 'http://www.w3.org/1998/Math/MathML';
|
||||
export declare const svg = 'http://www.w3.org/2000/svg';
|
||||
export declare const xlink = 'http://www.w3.org/1999/xlink';
|
||||
export declare const xml = 'http://www.w3.org/XML/1998/namespace';
|
||||
export declare const xmlns = 'http://www.w3.org/2000/xmlns';
|
||||
export declare const valid_namespaces: string[];
|
||||
export declare const namespaces: Record<string, string>;
|
||||
|
|
11
src/cli.ts
11
src/cli.ts
|
@ -22,9 +22,12 @@ function resolveArgs(flags: Arguments): cliState {
|
|||
|
||||
const cmd = flags._[2];
|
||||
switch (cmd) {
|
||||
case 'dev': return 'dev';
|
||||
case 'build': return 'build';
|
||||
default: return 'help';
|
||||
case 'dev':
|
||||
return 'dev';
|
||||
case 'build':
|
||||
return 'build';
|
||||
default:
|
||||
return 'help';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +81,7 @@ async function runCommand(rawRoot: string, cmd: (a: AstroConfig) => Promise<void
|
|||
|
||||
const cmdMap = new Map([
|
||||
['build', generate],
|
||||
['dev', devServer]
|
||||
['dev', devServer],
|
||||
]);
|
||||
|
||||
export async function cli(args: string[]) {
|
||||
|
|
6489
src/compiler.js
6489
src/compiler.js
File diff suppressed because it is too large
Load diff
23
src/dev.ts
23
src/dev.ts
|
@ -28,35 +28,36 @@ export default async function(astroConfig: AstroConfig) {
|
|||
};
|
||||
}
|
||||
|
||||
const snowpackConfig = await loadConfiguration({
|
||||
const snowpackConfig = await loadConfiguration(
|
||||
{
|
||||
root: projectRoot.pathname,
|
||||
mount: {
|
||||
[hmxRoot.pathname]: '/_hmx',
|
||||
[internalPath.pathname]: '/__hmx_internal__'
|
||||
[internalPath.pathname]: '/__hmx_internal__',
|
||||
},
|
||||
plugins: [
|
||||
['astro/snowpack-plugin', hmxPlugOptions]
|
||||
],
|
||||
plugins: [['astro/snowpack-plugin', hmxPlugOptions]],
|
||||
devOptions: {
|
||||
open: 'none',
|
||||
output: 'stream',
|
||||
port: 0
|
||||
port: 0,
|
||||
},
|
||||
packageOptions: {
|
||||
knownEntrypoints: ['preact-render-to-string'],
|
||||
external: ['@vue/server-renderer']
|
||||
}
|
||||
}, snowpackConfigPath.pathname);
|
||||
external: ['@vue/server-renderer'],
|
||||
},
|
||||
},
|
||||
snowpackConfigPath.pathname
|
||||
);
|
||||
const snowpack = await startSnowpackServer({
|
||||
config: snowpackConfig,
|
||||
lockfile: null
|
||||
lockfile: null,
|
||||
});
|
||||
const runtime = snowpack.getServerRuntime();
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
const fullurl = new URL(req.url || '/', 'https://example.org/');
|
||||
const reqPath = decodeURI(fullurl.pathname);
|
||||
const selectedPage = (reqPath.substr(1) || 'index');
|
||||
const selectedPage = reqPath.substr(1) || 'index';
|
||||
console.log(reqPath, selectedPage);
|
||||
|
||||
const selectedPageLoc = new URL(`./pages/${selectedPage}.hmx`, hmxRoot);
|
||||
|
|
|
@ -3,8 +3,7 @@ export type HChild = string | undefined | (() => string);
|
|||
export type HMXComponent = (props: HProps, ...children: Array<HChild>) => string;
|
||||
export type HTag = string | HMXComponent;
|
||||
|
||||
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr',
|
||||
'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
||||
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
||||
|
||||
function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
|
||||
yield `<${tag}`;
|
||||
|
|
|
@ -7,11 +7,11 @@ export function __vue_static(VueComponent: Component) {
|
|||
return async (attrs: Record<string, any>, ...children: any): Promise<string> => {
|
||||
const app = createSSRApp({
|
||||
components: {
|
||||
VueComponent
|
||||
VueComponent,
|
||||
},
|
||||
render() {
|
||||
return createElement(VueComponent as any, attrs);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const html = await renderToString(app);
|
||||
|
|
|
@ -24,15 +24,16 @@ export default async function(astroConfig: AstroConfig) {
|
|||
const dist = new URL(astroConfig.dist + '/', projectRoot);
|
||||
|
||||
const configPath = new URL('./snowpack.config.js', projectRoot).pathname;
|
||||
const config = await loadConfiguration({
|
||||
const config = await loadConfiguration(
|
||||
{
|
||||
root: projectRoot.pathname,
|
||||
devOptions:
|
||||
{open: 'none', output: 'stream'
|
||||
}
|
||||
}, configPath);
|
||||
devOptions: { open: 'none', output: 'stream' },
|
||||
},
|
||||
configPath
|
||||
);
|
||||
const snowpack = await startSnowpackServer({
|
||||
config,
|
||||
lockfile: null // TODO should this be required?
|
||||
lockfile: null, // TODO should this be required?
|
||||
});
|
||||
|
||||
const runtime = snowpack.getServerRuntime();
|
||||
|
|
|
@ -6,14 +6,14 @@ const characterReferences = {
|
|||
'<': 'lt',
|
||||
'>': 'gt',
|
||||
'{': 'lbrace',
|
||||
'}': 'rbrace'
|
||||
'}': 'rbrace',
|
||||
};
|
||||
|
||||
type EncodedChars = '"' | '&' | '<' | '>' | '{' | '}';
|
||||
|
||||
function encode(value: string): string {
|
||||
return value.replace(/["&<>{}]/g, (raw: string) => {
|
||||
return '&' + characterReferences[raw as EncodedChars] + ';'
|
||||
return '&' + characterReferences[raw as EncodedChars] + ';';
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -21,14 +21,12 @@ const plugin: HtmlExtension = {
|
|||
exit: {
|
||||
codeFlowValue() {
|
||||
const token: Token = arguments[0];
|
||||
const serialize = this.sliceSerialize as unknown as (t: Token) => string;
|
||||
const raw = this.raw as unknown as (s: string) => void;
|
||||
const serialize = (this.sliceSerialize as unknown) as (t: Token) => string;
|
||||
const raw = (this.raw as unknown) as (s: string) => void;
|
||||
const value = serialize(token);
|
||||
raw(encode(value));
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export {
|
||||
plugin as default
|
||||
};
|
||||
export { plugin as default };
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
const [
|
||||
CHARS,
|
||||
TAG_START,
|
||||
TAG_END,
|
||||
END_TAG_START,
|
||||
EQ,
|
||||
EOF,
|
||||
UNKNOWN
|
||||
] = Array.from(new Array(20), (x, i) => i + 1);
|
||||
const [CHARS, TAG_START, TAG_END, END_TAG_START, EQ, EOF, UNKNOWN] = Array.from(new Array(20), (x, i) => i + 1);
|
||||
|
||||
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr',
|
||||
'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
||||
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
||||
|
||||
type Visitor = (tag: Tag) => Tag;
|
||||
|
||||
|
@ -71,7 +62,7 @@ function createState(code: string, visitor: Visitor): State {
|
|||
return {
|
||||
code,
|
||||
index: 0,
|
||||
visitor
|
||||
visitor,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -114,7 +105,7 @@ function spliceSlice(str: string, index: number, count: number, add: string) {
|
|||
}
|
||||
}
|
||||
|
||||
return str.slice(0, index) + (add || "") + str.slice(index + count);
|
||||
return str.slice(0, index) + (add || '') + str.slice(index + count);
|
||||
}
|
||||
|
||||
function replaceTag(state: State, tag: Tag) {
|
||||
|
@ -170,7 +161,7 @@ function consumeText(state: State): Text {
|
|||
type: 0,
|
||||
data,
|
||||
start,
|
||||
end: state.index - 1
|
||||
end: state.index - 1,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -186,7 +177,8 @@ function consumeTagName(state: State): string {
|
|||
|
||||
function consumeAttribute(state: State): Attribute {
|
||||
let start = state.index;
|
||||
let name = '', token;
|
||||
let name = '',
|
||||
token;
|
||||
do {
|
||||
name += stateChar(state).toLowerCase();
|
||||
token = consumeToken(state);
|
||||
|
@ -198,7 +190,7 @@ function consumeAttribute(state: State): Attribute {
|
|||
name,
|
||||
boolean: true,
|
||||
start,
|
||||
end: state.index - 1
|
||||
end: state.index - 1,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -213,7 +205,7 @@ function consumeAttribute(state: State): Attribute {
|
|||
value,
|
||||
boolean: false,
|
||||
start,
|
||||
end: state.index - 1
|
||||
end: state.index - 1,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -279,7 +271,7 @@ function consumeTag(state: State): Tag {
|
|||
children,
|
||||
void: voidTags.has(tagName),
|
||||
start,
|
||||
end: state.index - 1
|
||||
end: state.index - 1,
|
||||
};
|
||||
|
||||
const replacement = state.visitor(node);
|
||||
|
@ -294,7 +286,7 @@ function consumeDocument(state: State): Document {
|
|||
const children: Array<Tag | Text> = consumeChildren(state);
|
||||
|
||||
return {
|
||||
children
|
||||
children,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import type { TemplateNode } from "./@types/compiler/interfaces";
|
||||
import type { TemplateNode } from './@types/compiler/interfaces';
|
||||
|
||||
import path from "path";
|
||||
import astring from "astring";
|
||||
import esbuild from "esbuild";
|
||||
import eslexer from "es-module-lexer";
|
||||
import micromark from "micromark";
|
||||
import gfmSyntax from "micromark-extension-gfm";
|
||||
import matter from "gray-matter";
|
||||
import path from 'path';
|
||||
import astring from 'astring';
|
||||
import esbuild from 'esbuild';
|
||||
import eslexer from 'es-module-lexer';
|
||||
import micromark from 'micromark';
|
||||
import gfmSyntax from 'micromark-extension-gfm';
|
||||
import matter from 'gray-matter';
|
||||
// @ts-ignore
|
||||
import gfmHtml from "micromark-extension-gfm/html.js";
|
||||
import { walk, parse } from "./compiler.js";
|
||||
import gfmHtml from 'micromark-extension-gfm/html.js';
|
||||
import { walk, parse } from './compiler.js';
|
||||
import markdownEncode from './markdown-encode.js';
|
||||
import { preparse } from './parser.js';
|
||||
|
||||
|
@ -18,18 +18,20 @@ const { transformSync } = esbuild;
|
|||
interface Attribute {
|
||||
start: 574;
|
||||
end: 595;
|
||||
type: "Attribute";
|
||||
name: "class";
|
||||
type: 'Attribute';
|
||||
name: 'class';
|
||||
value: any;
|
||||
}
|
||||
|
||||
interface CompileOptions {
|
||||
resolve: (p: string) => string
|
||||
resolve: (p: string) => string;
|
||||
}
|
||||
|
||||
const defaultCompileOptions: CompileOptions = {
|
||||
resolve(p: string) { return p; }
|
||||
}
|
||||
resolve(p: string) {
|
||||
return p;
|
||||
},
|
||||
};
|
||||
|
||||
function internalImport(internalPath: string) {
|
||||
return `/__hmx_internal__/${internalPath}`;
|
||||
|
@ -47,7 +49,7 @@ function getAttributes(attrs: Attribute[]): Record<string, string> {
|
|||
}
|
||||
if (attr.value.length > 1) {
|
||||
result[attr.name] =
|
||||
"(" +
|
||||
'(' +
|
||||
attr.value
|
||||
.map((v: TemplateNode) => {
|
||||
if (v.expression) {
|
||||
|
@ -56,21 +58,21 @@ function getAttributes(attrs: Attribute[]): Record<string, string> {
|
|||
return JSON.stringify(getTextFromAttribute(v));
|
||||
}
|
||||
})
|
||||
.join("+") +
|
||||
")";
|
||||
.join('+') +
|
||||
')';
|
||||
continue;
|
||||
}
|
||||
const val: TemplateNode = attr.value[0];
|
||||
switch (val.type) {
|
||||
case "MustacheTag":
|
||||
result[attr.name] = "(" + val.expression + ")";
|
||||
case 'MustacheTag':
|
||||
result[attr.name] = '(' + val.expression + ')';
|
||||
continue;
|
||||
case "Text":
|
||||
case 'Text':
|
||||
result[attr.name] = JSON.stringify(getTextFromAttribute(val));
|
||||
continue;
|
||||
default:
|
||||
console.log(val);
|
||||
throw new Error("UNKNOWN V");
|
||||
throw new Error('UNKNOWN V');
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -84,23 +86,19 @@ function getTextFromAttribute(attr: any): string {
|
|||
return attr.data;
|
||||
}
|
||||
console.log(attr);
|
||||
throw new Error("UNKNOWN attr");
|
||||
throw new Error('UNKNOWN attr');
|
||||
}
|
||||
|
||||
function generateAttributes(attrs: Record<string, string>): string {
|
||||
let result: string = "{";
|
||||
let result: string = '{';
|
||||
for (const [key, val] of Object.entries(attrs)) {
|
||||
result += JSON.stringify(key) + ":" + val + ",";
|
||||
result += JSON.stringify(key) + ':' + val + ',';
|
||||
}
|
||||
return result + "}";
|
||||
return result + '}';
|
||||
}
|
||||
|
||||
function getComponentWrapper(
|
||||
_name: string,
|
||||
{ type, url }: { type: string; url: string },
|
||||
{ resolve }: CompileOptions
|
||||
) {
|
||||
const [name, kind] = _name.split(":");
|
||||
function getComponentWrapper(_name: string, { type, url }: { type: string; url: string }, { resolve }: CompileOptions) {
|
||||
const [name, kind] = _name.split(':');
|
||||
switch (type) {
|
||||
case '.hmx': {
|
||||
if (kind) {
|
||||
|
@ -112,11 +110,9 @@ function getComponentWrapper(
|
|||
};
|
||||
}
|
||||
case '.jsx': {
|
||||
if (kind === "dynamic") {
|
||||
if (kind === 'dynamic') {
|
||||
return {
|
||||
wrapper: `__preact_dynamic(${name}, new URL(${JSON.stringify(
|
||||
url.replace(/\.[^.]+$/, ".js")
|
||||
)}, \`http://TEST\${import.meta.url}\`).pathname, '${resolve('preact')}')`,
|
||||
wrapper: `__preact_dynamic(${name}, new URL(${JSON.stringify(url.replace(/\.[^.]+$/, '.js'))}, \`http://TEST\${import.meta.url}\`).pathname, '${resolve('preact')}')`,
|
||||
wrapperImport: `import {__preact_dynamic} from '${internalImport('render/preact.js')}';`,
|
||||
};
|
||||
} else {
|
||||
|
@ -127,26 +123,22 @@ function getComponentWrapper(
|
|||
}
|
||||
}
|
||||
case '.svelte': {
|
||||
if(kind === "dynamic") {
|
||||
if (kind === 'dynamic') {
|
||||
return {
|
||||
wrapper: `__svelte_dynamic(${name}, new URL(${JSON.stringify(
|
||||
url.replace(/\.[^.]+$/, ".svelte.js")
|
||||
)}, \`http://TEST\${import.meta.url}\`).pathname)`,
|
||||
wrapper: `__svelte_dynamic(${name}, new URL(${JSON.stringify(url.replace(/\.[^.]+$/, '.svelte.js'))}, \`http://TEST\${import.meta.url}\`).pathname)`,
|
||||
wrapperImport: `import {__svelte_dynamic} from '${internalImport('render/svelte.js')}';`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
wrapper: `__svelte_static(${name})`,
|
||||
wrapperImport: `import {__svelte_static} from '${internalImport('render/svelte.js')}';`
|
||||
wrapperImport: `import {__svelte_static} from '${internalImport('render/svelte.js')}';`,
|
||||
};
|
||||
}
|
||||
}
|
||||
case '.vue': {
|
||||
if(kind === "dynamic") {
|
||||
if (kind === 'dynamic') {
|
||||
return {
|
||||
wrapper: `__vue_dynamic(${name}, new URL(${JSON.stringify(
|
||||
url.replace(/\.[^.]+$/, ".vue.js")
|
||||
)}, \`http://TEST\${import.meta.url}\`).pathname, '${resolve('vue')}')`,
|
||||
wrapper: `__vue_dynamic(${name}, new URL(${JSON.stringify(url.replace(/\.[^.]+$/, '.vue.js'))}, \`http://TEST\${import.meta.url}\`).pathname, '${resolve('vue')}')`,
|
||||
wrapperImport: `import {__vue_dynamic} from '${internalImport('render/vue.js')}';`,
|
||||
};
|
||||
} else {
|
||||
|
@ -154,16 +146,16 @@ function getComponentWrapper(
|
|||
wrapper: `__vue_static(${name})`,
|
||||
wrapperImport: `
|
||||
import {__vue_static} from '${internalImport('render/vue.js')}';
|
||||
`
|
||||
`,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error("Unknown Component Type: " + name);
|
||||
throw new Error('Unknown Component Type: ' + name);
|
||||
}
|
||||
|
||||
function runPreparser(template: string): string {
|
||||
const doc = preparse(template, tag => {
|
||||
const doc = preparse(template, (tag) => {
|
||||
if (tag.tagName === 'script') {
|
||||
let isSetup = false;
|
||||
for (let attr of tag.attributes) {
|
||||
|
@ -177,19 +169,21 @@ function runPreparser(template: string): string {
|
|||
|
||||
const content = tag.children[0];
|
||||
let { code } = transformSync(content, {
|
||||
loader: "tsx",
|
||||
jsxFactory: "h",
|
||||
jsxFragment: "Fragment",
|
||||
charset: "utf8",
|
||||
loader: 'tsx',
|
||||
jsxFactory: 'h',
|
||||
jsxFragment: 'Fragment',
|
||||
charset: 'utf8',
|
||||
});
|
||||
return {
|
||||
...tag,
|
||||
children: [{
|
||||
children: [
|
||||
{
|
||||
type: 0,
|
||||
data: code,
|
||||
start: 0,
|
||||
end: 0
|
||||
}]
|
||||
end: 0,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -209,9 +203,9 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions)
|
|||
|
||||
const ast = parse(template, {});
|
||||
// Todo: Validate that `h` and `Fragment` aren't defined in the script
|
||||
const script = ast.instance ? astring.generate(ast.instance.content) : "";
|
||||
const script = ast.instance ? astring.generate(ast.instance.content) : '';
|
||||
|
||||
const [scriptImports] = eslexer.parse(script, "optional-sourcename");
|
||||
const [scriptImports] = eslexer.parse(script, 'optional-sourcename');
|
||||
const components = Object.fromEntries(
|
||||
scriptImports.map((imp) => {
|
||||
const componentType = path.posix.extname(imp.n!);
|
||||
|
@ -222,7 +216,7 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions)
|
|||
|
||||
const additionalImports = new Set<string>();
|
||||
let items: { name: string; jsx: string }[] = [];
|
||||
let mode: "JSX" | "SCRIPT" | "SLOT" = "JSX";
|
||||
let mode: 'JSX' | 'SCRIPT' | 'SLOT' = 'JSX';
|
||||
let collectionItem: { name: string; jsx: string } | undefined;
|
||||
let currentItemName: string | undefined;
|
||||
let currentDepth = 0;
|
||||
|
@ -232,12 +226,12 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions)
|
|||
enter(node: TemplateNode, parent, prop, index) {
|
||||
// console.log("enter", node.type);
|
||||
switch (node.type) {
|
||||
case "MustacheTag":
|
||||
case 'MustacheTag':
|
||||
let { code } = transformSync(node.expression, {
|
||||
loader: "jsx",
|
||||
jsxFactory: "h",
|
||||
jsxFragment: "Fragment",
|
||||
charset: "utf8",
|
||||
loader: 'jsx',
|
||||
jsxFactory: 'h',
|
||||
jsxFragment: 'Fragment',
|
||||
charset: 'utf8',
|
||||
});
|
||||
|
||||
let matches: RegExpExecArray[] = [];
|
||||
|
@ -249,142 +243,127 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions)
|
|||
}
|
||||
for (const match of matches.reverse()) {
|
||||
const name = match[1];
|
||||
const [componentName, componentKind] = name.split(":");
|
||||
const [componentName, componentKind] = name.split(':');
|
||||
if (!components[componentName]) {
|
||||
throw new Error(`Unknown Component: ${componentName}`);
|
||||
}
|
||||
const { wrapper, wrapperImport } = getComponentWrapper(
|
||||
name,
|
||||
components[componentName],
|
||||
compileOptions
|
||||
);
|
||||
const { wrapper, wrapperImport } = getComponentWrapper(name, components[componentName], compileOptions);
|
||||
if (wrapperImport) {
|
||||
additionalImports.add(wrapperImport);
|
||||
}
|
||||
if (wrapper !== name) {
|
||||
code =
|
||||
code.slice(0, match.index + 2) +
|
||||
wrapper +
|
||||
code.slice(match.index + match[0].length - 1);
|
||||
code = code.slice(0, match.index + 2) + wrapper + code.slice(match.index + match[0].length - 1);
|
||||
}
|
||||
}
|
||||
collectionItem!.jsx += `,(${code.trim().replace(/\;$/, "")})`;
|
||||
collectionItem!.jsx += `,(${code.trim().replace(/\;$/, '')})`;
|
||||
return;
|
||||
case "Slot":
|
||||
mode = "SLOT";
|
||||
case 'Slot':
|
||||
mode = 'SLOT';
|
||||
collectionItem!.jsx += `,child`;
|
||||
return;
|
||||
case "Comment":
|
||||
case 'Comment':
|
||||
return;
|
||||
case "Fragment":
|
||||
case 'Fragment':
|
||||
// Ignore if its the top level fragment
|
||||
// This should be cleaned up, but right now this is how the old thing worked
|
||||
if (!collectionItem) {
|
||||
return;
|
||||
}
|
||||
case "InlineComponent":
|
||||
case "Element":
|
||||
case 'InlineComponent':
|
||||
case 'Element':
|
||||
const name: string = node.name;
|
||||
if (!name) {
|
||||
console.log(node);
|
||||
throw new Error("AHHHH");
|
||||
throw new Error('AHHHH');
|
||||
}
|
||||
const attributes = getAttributes(node.attributes);
|
||||
currentDepth++;
|
||||
currentItemName = name;
|
||||
if (!collectionItem) {
|
||||
collectionItem = { name, jsx: "" };
|
||||
collectionItem = { name, jsx: '' };
|
||||
items.push(collectionItem);
|
||||
}
|
||||
collectionItem.jsx += collectionItem.jsx === "" ? "" : ",";
|
||||
collectionItem.jsx += collectionItem.jsx === '' ? '' : ',';
|
||||
const COMPONENT_NAME_SCANNER = /^[A-Z]/;
|
||||
if (!COMPONENT_NAME_SCANNER.test(name)) {
|
||||
collectionItem.jsx += `h("${name}", ${
|
||||
attributes ? generateAttributes(attributes) : "null"
|
||||
}`;
|
||||
collectionItem.jsx += `h("${name}", ${attributes ? generateAttributes(attributes) : 'null'}`;
|
||||
return;
|
||||
}
|
||||
if (name === 'Component') {
|
||||
collectionItem.jsx += `h(Fragment, null`;
|
||||
return;
|
||||
}
|
||||
const [componentName, componentKind] = name.split(":");
|
||||
const [componentName, componentKind] = name.split(':');
|
||||
const componentImportData = components[componentName];
|
||||
if (!componentImportData) {
|
||||
throw new Error(`Unknown Component: ${componentName}`);
|
||||
}
|
||||
const { wrapper, wrapperImport } = getComponentWrapper(
|
||||
name,
|
||||
components[componentName],
|
||||
compileOptions
|
||||
);
|
||||
const { wrapper, wrapperImport } = getComponentWrapper(name, components[componentName], compileOptions);
|
||||
if (wrapperImport) {
|
||||
additionalImports.add(wrapperImport);
|
||||
}
|
||||
collectionItem.jsx += `h(${wrapper}, ${
|
||||
attributes ? generateAttributes(attributes) : "null"
|
||||
}`;
|
||||
collectionItem.jsx += `h(${wrapper}, ${attributes ? generateAttributes(attributes) : 'null'}`;
|
||||
return;
|
||||
case "Attribute": {
|
||||
case 'Attribute': {
|
||||
this.skip();
|
||||
return;
|
||||
}
|
||||
case "Text": {
|
||||
case 'Text': {
|
||||
const text = getTextFromAttribute(node);
|
||||
if (mode === "SLOT") {
|
||||
if (mode === 'SLOT') {
|
||||
return;
|
||||
}
|
||||
if (!text.trim()) {
|
||||
return;
|
||||
}
|
||||
if (!collectionItem) {
|
||||
throw new Error("Not possible! TEXT:" + text);
|
||||
throw new Error('Not possible! TEXT:' + text);
|
||||
}
|
||||
if (currentItemName === "script" || currentItemName === "code") {
|
||||
collectionItem.jsx += "," + JSON.stringify(text);
|
||||
if (currentItemName === 'script' || currentItemName === 'code') {
|
||||
collectionItem.jsx += ',' + JSON.stringify(text);
|
||||
return;
|
||||
}
|
||||
collectionItem.jsx += "," + JSON.stringify(text);
|
||||
collectionItem.jsx += ',' + JSON.stringify(text);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
console.log(node);
|
||||
throw new Error("Unexpected node type: " + node.type);
|
||||
throw new Error('Unexpected node type: ' + node.type);
|
||||
}
|
||||
},
|
||||
// @ts-ignore
|
||||
leave(node: TemplateNode, parent, prop, index) {
|
||||
// console.log("leave", node.type);
|
||||
switch (node.type) {
|
||||
case "Text":
|
||||
case "MustacheTag":
|
||||
case "Attribute":
|
||||
case "Comment":
|
||||
case 'Text':
|
||||
case 'MustacheTag':
|
||||
case 'Attribute':
|
||||
case 'Comment':
|
||||
return;
|
||||
case "Slot": {
|
||||
case 'Slot': {
|
||||
const name = node.name;
|
||||
if (name === "slot") {
|
||||
mode = "JSX";
|
||||
if (name === 'slot') {
|
||||
mode = 'JSX';
|
||||
}
|
||||
return;
|
||||
}
|
||||
case "Fragment":
|
||||
case 'Fragment':
|
||||
if (!collectionItem) {
|
||||
return;
|
||||
}
|
||||
case "Element":
|
||||
case "InlineComponent":
|
||||
case 'Element':
|
||||
case 'InlineComponent':
|
||||
if (!collectionItem) {
|
||||
throw new Error("Not possible! CLOSE " + node.name);
|
||||
throw new Error('Not possible! CLOSE ' + node.name);
|
||||
}
|
||||
collectionItem.jsx += ")";
|
||||
collectionItem.jsx += ')';
|
||||
currentDepth--;
|
||||
if (currentDepth === 0) {
|
||||
collectionItem = undefined;
|
||||
}
|
||||
return;
|
||||
default:
|
||||
throw new Error("Unexpected node type: " + node.type);
|
||||
throw new Error('Unexpected node type: ' + node.type);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -398,7 +377,7 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions)
|
|||
*/
|
||||
|
||||
return {
|
||||
script: script + "\n" + Array.from(additionalImports).join("\n"),
|
||||
script: script + '\n' + Array.from(additionalImports).join('\n'),
|
||||
items,
|
||||
};
|
||||
}
|
||||
|
@ -427,36 +406,31 @@ async function convertMdToJsx(contents: string, compileOptions: CompileOptions)
|
|||
},
|
||||
};
|
||||
|
||||
return convertHmxToJsx(`<script hmx="setup">export function setup() {
|
||||
return convertHmxToJsx(
|
||||
`<script hmx="setup">export function setup() {
|
||||
return ${JSON.stringify(setupData)};
|
||||
}</script><head></head><body>${mdHtml}</body>`, compileOptions);
|
||||
}</script><head></head><body>${mdHtml}</body>`,
|
||||
compileOptions
|
||||
);
|
||||
}
|
||||
|
||||
async function transformFromSource(
|
||||
contents: string,
|
||||
filename: string,
|
||||
compileOptions: CompileOptions
|
||||
): Promise<ReturnType<typeof convertHmxToJsx>> {
|
||||
async function transformFromSource(contents: string, filename: string, compileOptions: CompileOptions): Promise<ReturnType<typeof convertHmxToJsx>> {
|
||||
switch (path.extname(filename)) {
|
||||
case ".hmx":
|
||||
case '.hmx':
|
||||
return convertHmxToJsx(contents, compileOptions);
|
||||
case ".md":
|
||||
case '.md':
|
||||
return convertMdToJsx(contents, compileOptions);
|
||||
default:
|
||||
throw new Error("Not Supported!");
|
||||
throw new Error('Not Supported!');
|
||||
}
|
||||
}
|
||||
|
||||
export async function compilePage(source: string, filename: string, opts: CompileOptions = defaultCompileOptions) {
|
||||
const sourceJsx = await transformFromSource(source, filename, opts);
|
||||
const headItem = sourceJsx.items.find((item) => item.name === "head");
|
||||
const bodyItem = sourceJsx.items.find((item) => item.name === "body");
|
||||
const headItemJsx = !headItem
|
||||
? "null"
|
||||
: headItem.jsx.replace('"head"', 'isRoot ? "head" : Fragment');
|
||||
const bodyItemJsx = !bodyItem
|
||||
? "null"
|
||||
: bodyItem.jsx.replace('"head"', 'isRoot ? "body" : Fragment');
|
||||
const headItem = sourceJsx.items.find((item) => item.name === 'head');
|
||||
const bodyItem = sourceJsx.items.find((item) => item.name === 'body');
|
||||
const headItemJsx = !headItem ? 'null' : headItem.jsx.replace('"head"', 'isRoot ? "head" : Fragment');
|
||||
const bodyItemJsx = !bodyItem ? 'null' : bodyItem.jsx.replace('"head"', 'isRoot ? "body" : Fragment');
|
||||
|
||||
const modJsx = `
|
||||
${sourceJsx.script}
|
||||
|
@ -473,9 +447,7 @@ export function body({title, description, props}, child, isRoot) { return (${bod
|
|||
|
||||
export async function compileComponent(source: string, filename: string, opts: CompileOptions = defaultCompileOptions) {
|
||||
const sourceJsx = await transformFromSource(source, filename, opts);
|
||||
const componentJsx = sourceJsx.items.find(
|
||||
(item) => item.name === "Component"
|
||||
);
|
||||
const componentJsx = sourceJsx.items.find((item) => item.name === 'Component');
|
||||
if (!componentJsx) {
|
||||
throw new Error(`${filename} <Component> expected!`);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue