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": {
|
"scripts": {
|
||||||
"build": "tsc && npm run copy-js",
|
"build": "tsc && npm run copy-js",
|
||||||
|
"lint": "eslint 'src/**/*.{js,ts}'",
|
||||||
"dev": "concurrently 'tsc --watch' 'npm run copy-js:watch'",
|
"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": "copyfiles -u 1 src/*.js lib/",
|
||||||
"copy-js:watch": "nodemon -w src --ext js --exec 'npm run copy-js'"
|
"copy-js:watch": "nodemon -w src --ext js --exec 'npm run copy-js'"
|
||||||
},
|
},
|
||||||
|
@ -45,12 +47,18 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/yargs-parser": "^20.2.0",
|
"@types/yargs-parser": "^20.2.0",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^4.18.0",
|
||||||
|
"@typescript-eslint/parser": "^4.18.0",
|
||||||
"concurrently": "^6.0.0",
|
"concurrently": "^6.0.0",
|
||||||
"copyfiles": "^2.4.1",
|
"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",
|
"estree-walker": "^3.0.0",
|
||||||
"nodemon": "^2.0.7",
|
"nodemon": "^2.0.7",
|
||||||
"preact": "^10.5.12",
|
"preact": "^10.5.12",
|
||||||
"preact-render-to-string": "^5.1.14",
|
"preact-render-to-string": "^5.1.14",
|
||||||
|
"prettier": "^2.2.1",
|
||||||
"typescript": "^4.2.3"
|
"typescript": "^4.2.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
export interface AstroConfigRaw {
|
export interface AstroConfigRaw {
|
||||||
dist: string;
|
dist: string;
|
||||||
projectRoot: 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[];
|
imports: ImportDeclaration[];
|
||||||
hoistable_nodes: Set<Node>;
|
hoistable_nodes: Set<Node>;
|
||||||
node_for_declaration: Map<string, Node>;
|
node_for_declaration: Map<string, Node>;
|
||||||
partly_hoisted: Array<(Node | Node[])>;
|
partly_hoisted: Array<Node | Node[]>;
|
||||||
fully_hoisted: Array<(Node | Node[])>;
|
fully_hoisted: Array<Node | Node[]>;
|
||||||
reactive_declarations: Array<{
|
reactive_declarations: Array<{
|
||||||
assignees: Set<string>;
|
assignees: Set<string>;
|
||||||
dependencies: Set<string>;
|
dependencies: Set<string>;
|
||||||
|
@ -52,7 +52,9 @@ export default class Component {
|
||||||
globals: Map<string, Identifier>;
|
globals: Map<string, Identifier>;
|
||||||
indirect_dependencies: Map<string, Set<string>>;
|
indirect_dependencies: Map<string, Set<string>>;
|
||||||
file: string;
|
file: string;
|
||||||
locate: (c: number) => {
|
locate: (
|
||||||
|
c: number
|
||||||
|
) => {
|
||||||
line: number;
|
line: number;
|
||||||
column: number;
|
column: number;
|
||||||
};
|
};
|
||||||
|
@ -96,20 +98,26 @@ export default class Component {
|
||||||
};
|
};
|
||||||
get_unique_name(name: string, scope?: Scope): Identifier;
|
get_unique_name(name: string, scope?: Scope): Identifier;
|
||||||
get_unique_name_maker(): (name: string) => Identifier;
|
get_unique_name_maker(): (name: string) => Identifier;
|
||||||
error(pos: {
|
error(
|
||||||
|
pos: {
|
||||||
start: number;
|
start: number;
|
||||||
end: number;
|
end: number;
|
||||||
}, e: {
|
},
|
||||||
|
e: {
|
||||||
code: string;
|
code: string;
|
||||||
message: string;
|
message: string;
|
||||||
}): void;
|
}
|
||||||
warn(pos: {
|
): void;
|
||||||
|
warn(
|
||||||
|
pos: {
|
||||||
start: number;
|
start: number;
|
||||||
end: number;
|
end: number;
|
||||||
}, warning: {
|
},
|
||||||
|
warning: {
|
||||||
code: string;
|
code: string;
|
||||||
message: string;
|
message: string;
|
||||||
}): void;
|
}
|
||||||
|
): void;
|
||||||
extract_imports(node: any): void;
|
extract_imports(node: any): void;
|
||||||
extract_exports(node: any): any;
|
extract_exports(node: any): any;
|
||||||
extract_javascript(script: 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;
|
name: string;
|
||||||
as: 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;
|
name: string;
|
||||||
alias: Identifier;
|
alias: Identifier;
|
||||||
}>, globals: Array<{
|
}>,
|
||||||
|
globals: Array<{
|
||||||
name: string;
|
name: string;
|
||||||
alias: Identifier;
|
alias: Identifier;
|
||||||
}>, imports: ImportDeclaration[], module_exports: Export[]): void;
|
}>,
|
||||||
|
imports: ImportDeclaration[],
|
||||||
|
module_exports: Export[]
|
||||||
|
): void;
|
||||||
export {};
|
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>;
|
children: Array<Rule | Atrule>;
|
||||||
keyframes: Map<string, string>;
|
keyframes: Map<string, string>;
|
||||||
nodes_with_css_class: Set<CssNode>;
|
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;
|
source: string;
|
||||||
ast: Ast;
|
ast: Ast;
|
||||||
filename: string | undefined;
|
filename: string | undefined;
|
||||||
|
@ -57,9 +64,12 @@ export default class Stylesheet {
|
||||||
});
|
});
|
||||||
apply(node: Element): void;
|
apply(node: Element): void;
|
||||||
reify(): void;
|
reify(): void;
|
||||||
render(file: string, should_transform_selectors: boolean): {
|
render(
|
||||||
|
file: string,
|
||||||
|
should_transform_selectors: boolean
|
||||||
|
): {
|
||||||
code: string;
|
code: string;
|
||||||
map: import("magic-string").SourceMap;
|
map: import('magic-string').SourceMap;
|
||||||
};
|
};
|
||||||
validate(component: Component): void;
|
validate(component: Component): void;
|
||||||
warn_on_unused_selectors(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';
|
import { CompileOptions, Warning } from '../interfaces';
|
||||||
export default function compile(source: string, options?: CompileOptions): {
|
export default function compile(
|
||||||
|
source: string,
|
||||||
|
options?: CompileOptions
|
||||||
|
): {
|
||||||
js: any;
|
js: any;
|
||||||
css: any;
|
css: any;
|
||||||
ast: import("../interfaces").Ast;
|
ast: import('../interfaces').Ast;
|
||||||
warnings: Warning[];
|
warnings: Warning[];
|
||||||
vars: {
|
vars: {
|
||||||
name: string;
|
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>;
|
dependencies: Set<string>;
|
||||||
constructor(component: Component, parent: Node, scope: TemplateScope, info: TemplateNode);
|
constructor(component: Component, parent: Node, scope: TemplateScope, info: TemplateNode);
|
||||||
get_dependencies(): string[];
|
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;
|
type: string;
|
||||||
value: string;
|
value: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,4 +31,37 @@ import ThenBlock from './ThenBlock';
|
||||||
import Title from './Title';
|
import Title from './Title';
|
||||||
import Transition from './Transition';
|
import Transition from './Transition';
|
||||||
import Window from './Window';
|
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;
|
template_scope: TemplateScope;
|
||||||
scope: Scope;
|
scope: Scope;
|
||||||
scope_map: WeakMap<Node, Scope>;
|
scope_map: WeakMap<Node, Scope>;
|
||||||
declarations: Array<(Node | Node[])>;
|
declarations: Array<Node | Node[]>;
|
||||||
uses_context: boolean;
|
uses_context: boolean;
|
||||||
manipulated: Node;
|
manipulated: Node;
|
||||||
constructor(component: Component, owner: Owner, template_scope: TemplateScope, info: Node, lazy?: boolean);
|
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 Window from '../Window';
|
||||||
import { TemplateNode } from '../../../interfaces';
|
import { TemplateNode } from '../../../interfaces';
|
||||||
export declare type Children = ReturnType<typeof map_children>;
|
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;
|
has_outro_method: boolean;
|
||||||
outros: number;
|
outros: number;
|
||||||
aliases: Map<string, Identifier>;
|
aliases: Map<string, Identifier>;
|
||||||
variables: Map<string, {
|
variables: Map<
|
||||||
|
string,
|
||||||
|
{
|
||||||
id: Identifier;
|
id: Identifier;
|
||||||
init?: Node;
|
init?: Node;
|
||||||
}>;
|
}
|
||||||
|
>;
|
||||||
get_unique_name: (name: string) => Identifier;
|
get_unique_name: (name: string) => Identifier;
|
||||||
has_update_method: boolean;
|
has_update_method: boolean;
|
||||||
autofocus: string;
|
autofocus: string;
|
||||||
|
|
|
@ -21,17 +21,22 @@ export default class Renderer {
|
||||||
blocks: Array<Block | Node | Node[]>;
|
blocks: Array<Block | Node | Node[]>;
|
||||||
readonly: Set<string>;
|
readonly: Set<string>;
|
||||||
meta_bindings: Array<Node | Node[]>;
|
meta_bindings: Array<Node | Node[]>;
|
||||||
binding_groups: Map<string, {
|
binding_groups: Map<
|
||||||
|
string,
|
||||||
|
{
|
||||||
binding_group: (to_reference?: boolean) => Node;
|
binding_group: (to_reference?: boolean) => Node;
|
||||||
is_context: boolean;
|
is_context: boolean;
|
||||||
contexts: string[];
|
contexts: string[];
|
||||||
index: number;
|
index: number;
|
||||||
keypath: string;
|
keypath: string;
|
||||||
}>;
|
}
|
||||||
|
>;
|
||||||
block: Block;
|
block: Block;
|
||||||
fragment: FragmentWrapper;
|
fragment: FragmentWrapper;
|
||||||
file_var: Identifier;
|
file_var: Identifier;
|
||||||
locate: (c: number) => {
|
locate: (
|
||||||
|
c: number
|
||||||
|
) => {
|
||||||
line: number;
|
line: number;
|
||||||
column: number;
|
column: number;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import Component from '../Component';
|
import Component from '../Component';
|
||||||
import { CompileOptions, CssResult } from '../../interfaces';
|
import { CompileOptions, CssResult } from '../../interfaces';
|
||||||
import { Node } from 'estree';
|
import { Node } from 'estree';
|
||||||
export default function dom(component: Component, options: CompileOptions): {
|
export default function dom(
|
||||||
|
component: Component,
|
||||||
|
options: CompileOptions
|
||||||
|
): {
|
||||||
js: Node[];
|
js: Node[];
|
||||||
css: CssResult;
|
css: CssResult;
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,7 +21,15 @@ declare class AwaitBlockBranch extends Wrapper {
|
||||||
value_index: Literal;
|
value_index: Literal;
|
||||||
value_contexts: Context[];
|
value_contexts: Context[];
|
||||||
is_destructured: boolean;
|
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;
|
add_context(node: Node | null, contexts: Context[]): void;
|
||||||
render(block: Block, parent_node: Identifier, parent_nodes: Identifier): void;
|
render(block: Block, parent_node: Identifier, parent_nodes: Identifier): void;
|
||||||
render_destructure(): void;
|
render_destructure(): void;
|
||||||
|
|
|
@ -34,7 +34,16 @@ export default class EachBlockWrapper extends Wrapper {
|
||||||
var: Identifier;
|
var: Identifier;
|
||||||
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: EachBlock, strip_whitespace: boolean, next_sibling: Wrapper);
|
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(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;
|
block: Block;
|
||||||
parent_node: Identifier;
|
parent_node: Identifier;
|
||||||
parent_nodes: Identifier;
|
parent_nodes: Identifier;
|
||||||
|
@ -44,7 +53,15 @@ export default class EachBlockWrapper extends Wrapper {
|
||||||
update_anchor_node: Identifier;
|
update_anchor_node: Identifier;
|
||||||
update_mount_node: Identifier;
|
update_mount_node: Identifier;
|
||||||
}): void;
|
}): 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;
|
block: Block;
|
||||||
parent_nodes: Identifier;
|
parent_nodes: Identifier;
|
||||||
snippet: Node;
|
snippet: Node;
|
||||||
|
|
|
@ -26,17 +26,234 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
|
||||||
get_dom_update_conditions(block: Block, dependency_condition: Node): Node;
|
get_dom_update_conditions(block: Block, dependency_condition: Node): Node;
|
||||||
get_dependencies(): string[];
|
get_dependencies(): string[];
|
||||||
get_metadata(): any;
|
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;
|
type: string;
|
||||||
value: 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;
|
type: string;
|
||||||
value: 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;
|
type: string;
|
||||||
value: string;
|
value: string;
|
||||||
})[];
|
}
|
||||||
|
)[];
|
||||||
stringify(): string;
|
stringify(): string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ export default class BindingWrapper {
|
||||||
object: string;
|
object: string;
|
||||||
handler: {
|
handler: {
|
||||||
uses_context: boolean;
|
uses_context: boolean;
|
||||||
mutation: (Node | Node[]);
|
mutation: Node | Node[];
|
||||||
contextual_dependencies: Set<string>;
|
contextual_dependencies: Set<string>;
|
||||||
lhs?: Node;
|
lhs?: Node;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
import { BaseAttributeWrapper } from './Attribute';
|
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);
|
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;
|
render(block: Block, parent_node: Identifier, parent_nodes: Identifier): void;
|
||||||
can_use_textcontent(): boolean;
|
can_use_textcontent(): boolean;
|
||||||
get_render_statement(block: Block): import("estree").Expression;
|
get_render_statement(block: Block): import('estree').Expression;
|
||||||
get_claim_statement(nodes: Identifier): import("estree").Expression;
|
get_claim_statement(nodes: Identifier): import('estree').Expression;
|
||||||
add_directives_in_order(block: Block): void;
|
add_directives_in_order(block: Block): void;
|
||||||
add_bindings(block: Block, binding_group: BindingGroup): void;
|
add_bindings(block: Block, binding_group: BindingGroup): void;
|
||||||
add_this_binding(block: Block, this_binding: Binding): void;
|
add_this_binding(block: Block, this_binding: Binding): void;
|
||||||
|
|
|
@ -23,32 +23,70 @@ export default class IfBlockWrapper extends Wrapper {
|
||||||
var: Identifier;
|
var: Identifier;
|
||||||
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: EachBlock, strip_whitespace: boolean, next_sibling: Wrapper);
|
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(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;
|
name: any;
|
||||||
anchor: any;
|
anchor: any;
|
||||||
has_else: any;
|
has_else: any;
|
||||||
if_exists_condition: any;
|
if_exists_condition: any;
|
||||||
has_transitions: 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;
|
name: any;
|
||||||
anchor: any;
|
anchor: any;
|
||||||
has_else: any;
|
has_else: any;
|
||||||
has_transitions: any;
|
has_transitions: any;
|
||||||
if_exists_condition: 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;
|
name: any;
|
||||||
anchor: any;
|
anchor: any;
|
||||||
if_exists_condition: any;
|
if_exists_condition: any;
|
||||||
has_transitions: any;
|
has_transitions: any;
|
||||||
}, detaching: any): void;
|
},
|
||||||
|
detaching: any
|
||||||
|
): void;
|
||||||
get_initial_dirty_bit(): {
|
get_initial_dirty_bit(): {
|
||||||
readonly type: "ArrayExpression" | "UnaryExpression";
|
readonly type: 'ArrayExpression' | 'UnaryExpression';
|
||||||
elements: UnaryExpression[];
|
elements: UnaryExpression[];
|
||||||
operator: import("estree").UnaryOperator;
|
operator: import('estree').UnaryOperator;
|
||||||
prefix: true;
|
prefix: true;
|
||||||
argument: import("estree").Expression;
|
argument: import('estree').Expression;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export {};
|
export {};
|
||||||
|
|
|
@ -8,7 +8,79 @@ export default class Tag extends Wrapper {
|
||||||
node: MustacheTag | RawMustacheTag;
|
node: MustacheTag | RawMustacheTag;
|
||||||
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: MustacheTag | RawMustacheTag);
|
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: MustacheTag | RawMustacheTag);
|
||||||
is_dependencies_static(): boolean;
|
is_dependencies_static(): boolean;
|
||||||
rename_this_method(block: Block, update: ((value: Node) => (Node | Node[]))): {
|
rename_this_method(
|
||||||
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;
|
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 Block from '../../Block';
|
||||||
import BindingWrapper from '../Element/Binding';
|
import BindingWrapper from '../Element/Binding';
|
||||||
import { Identifier } from 'estree';
|
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 Let from '../../../nodes/Let';
|
||||||
import Block from '../../Block';
|
import Block from '../../Block';
|
||||||
import TemplateScope from '../../../nodes/shared/TemplateScope';
|
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;
|
block: Block;
|
||||||
scope: TemplateScope;
|
scope: TemplateScope;
|
||||||
get_context?: undefined;
|
get_context?: undefined;
|
||||||
get_changes?: undefined;
|
get_changes?: undefined;
|
||||||
} | {
|
}
|
||||||
|
| {
|
||||||
block: Block;
|
block: Block;
|
||||||
scope: TemplateScope;
|
scope: TemplateScope;
|
||||||
get_context: import("estree").Expression;
|
get_context: import('estree').Expression;
|
||||||
get_changes: import("estree").Expression;
|
get_changes: import('estree').Expression;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,9 @@ import { AppendTarget, CompileOptions } from '../../interfaces';
|
||||||
import { INode } from '../nodes/interfaces';
|
import { INode } from '../nodes/interfaces';
|
||||||
import { Expression, TemplateLiteral, Identifier } from 'estree';
|
import { Expression, TemplateLiteral, Identifier } from 'estree';
|
||||||
export interface RenderOptions extends CompileOptions {
|
export interface RenderOptions extends CompileOptions {
|
||||||
locate: (c: number) => {
|
locate: (
|
||||||
|
c: number
|
||||||
|
) => {
|
||||||
line: number;
|
line: number;
|
||||||
column: number;
|
column: number;
|
||||||
};
|
};
|
||||||
|
@ -22,9 +24,7 @@ export default class Renderer {
|
||||||
};
|
};
|
||||||
literal: TemplateLiteral;
|
literal: TemplateLiteral;
|
||||||
targets: AppendTarget[];
|
targets: AppendTarget[];
|
||||||
constructor({ name }: {
|
constructor({ name }: { name: any });
|
||||||
name: any;
|
|
||||||
});
|
|
||||||
add_string(str: string): void;
|
add_string(str: string): void;
|
||||||
add_expression(node: Expression): void;
|
add_expression(node: Expression): void;
|
||||||
push(): void;
|
push(): void;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import Renderer, { RenderOptions } from '../Renderer';
|
import Renderer, { RenderOptions } from '../Renderer';
|
||||||
import Slot from '../../nodes/Slot';
|
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>;
|
slot_scopes: Map<any, any>;
|
||||||
}): void;
|
}
|
||||||
|
): void;
|
||||||
|
|
|
@ -2,6 +2,10 @@ import Renderer, { RenderOptions } from '../Renderer';
|
||||||
import SlotTemplate from '../../nodes/SlotTemplate';
|
import SlotTemplate from '../../nodes/SlotTemplate';
|
||||||
import InlineComponent from '../../nodes/InlineComponent';
|
import InlineComponent from '../../nodes/InlineComponent';
|
||||||
import Element from '../../nodes/Element';
|
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>;
|
slot_scopes: Map<any, any>;
|
||||||
}): void;
|
}
|
||||||
|
): void;
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import Component from '../Component';
|
import Component from '../Component';
|
||||||
import { CompileOptions, CssResult } from '../../interfaces';
|
import { CompileOptions, CssResult } from '../../interfaces';
|
||||||
import { Node } from 'estree';
|
import { Node } from 'estree';
|
||||||
export default function ssr(component: Component, options: CompileOptions): {
|
export default function ssr(
|
||||||
|
component: Component,
|
||||||
|
options: CompileOptions
|
||||||
|
): {
|
||||||
js: Node[];
|
js: Node[];
|
||||||
css: CssResult;
|
css: CssResult;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { Node } from 'estree';
|
import { Node } from 'estree';
|
||||||
export default function flatten_reference(node: Node): {
|
export default function flatten_reference(
|
||||||
|
node: Node
|
||||||
|
): {
|
||||||
name: string;
|
name: string;
|
||||||
nodes: any[];
|
nodes: any[];
|
||||||
parts: any[];
|
parts: any[];
|
||||||
|
|
|
@ -1,9 +1,85 @@
|
||||||
import Attribute from '../nodes/Attribute';
|
import Attribute from '../nodes/Attribute';
|
||||||
import Block from '../render_dom/Block';
|
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;
|
type: string;
|
||||||
properties: (import("estree").Property | import("estree").SpreadElement | {
|
properties: (
|
||||||
|
| import('estree').Property
|
||||||
|
| import('estree').SpreadElement
|
||||||
|
| {
|
||||||
type: string;
|
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';
|
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 { Node } from 'estree';
|
||||||
import { Scope, extract_names, extract_identifiers } from 'periscopic';
|
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>;
|
map: WeakMap<Node, Scope>;
|
||||||
scope: Scope;
|
scope: Scope;
|
||||||
globals: Map<string, Node>;
|
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;
|
type: string;
|
||||||
value: 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;
|
only_escape_at_symbol?: boolean;
|
||||||
}): string;
|
}
|
||||||
|
): string;
|
||||||
export declare function escape_html(html: any): string;
|
export declare function escape_html(html: any): string;
|
||||||
export declare function escape_template(str: any): any;
|
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 parse } from './parse/index';
|
||||||
export { default as preprocess } from './preprocess/index';
|
export { default as preprocess } from './preprocess/index';
|
||||||
export { walk } from 'estree-walker';
|
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;
|
toString: () => string;
|
||||||
}
|
}
|
||||||
export declare type ModuleFormat = 'esm' | 'cjs';
|
export declare type ModuleFormat = 'esm' | 'cjs';
|
||||||
export declare type CssHashGetter = (args: {
|
export declare type CssHashGetter = (args: { name: string; filename: string | undefined; css: string; hash: (input: string) => string }) => string;
|
||||||
name: string;
|
|
||||||
filename: string | undefined;
|
|
||||||
css: string;
|
|
||||||
hash: (input: string) => string;
|
|
||||||
}) => string;
|
|
||||||
export interface CompileOptions {
|
export interface CompileOptions {
|
||||||
format?: ModuleFormat;
|
format?: ModuleFormat;
|
||||||
name?: string;
|
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);
|
constructor(template: string, options: ParserOptions);
|
||||||
current(): TemplateNode;
|
current(): TemplateNode;
|
||||||
acorn_error(err: any): void;
|
acorn_error(err: any): void;
|
||||||
error({ code, message }: {
|
error(
|
||||||
|
{
|
||||||
|
code,
|
||||||
|
message,
|
||||||
|
}: {
|
||||||
code: string;
|
code: string;
|
||||||
message: string;
|
message: string;
|
||||||
}, index?: number): void;
|
},
|
||||||
|
index?: number
|
||||||
|
): void;
|
||||||
eat(str: string, required?: boolean, message?: string): boolean;
|
eat(str: string, required?: boolean, message?: string): boolean;
|
||||||
match(str: string): boolean;
|
match(str: string): boolean;
|
||||||
match_regex(pattern: RegExp): string;
|
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 { Parser } from '../index';
|
||||||
import { Pattern } from 'estree';
|
import { Pattern } from 'estree';
|
||||||
export default function read_context(parser: Parser): Pattern & {
|
export default function read_context(
|
||||||
|
parser: Parser
|
||||||
|
): Pattern & {
|
||||||
start: number;
|
start: number;
|
||||||
end: 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';
|
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;
|
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[];
|
dependencies?: string[];
|
||||||
toString?: () => string;
|
toString?: () => string;
|
||||||
}
|
}
|
||||||
export declare type MarkupPreprocessor = (options: {
|
export declare type MarkupPreprocessor = (options: { content: string; filename: string }) => Processed | Promise<Processed>;
|
||||||
content: string;
|
export declare type Preprocessor = (options: { content: string; attributes: Record<string, string | boolean>; filename?: string }) => Processed | Promise<Processed>;
|
||||||
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 {
|
export interface PreprocessorGroup {
|
||||||
markup?: MarkupPreprocessor;
|
markup?: MarkupPreprocessor;
|
||||||
style?: Preprocessor;
|
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;
|
name: string;
|
||||||
code: string;
|
code: string;
|
||||||
source: string;
|
source: string;
|
||||||
filename: string;
|
filename: string;
|
||||||
start: number;
|
start: number;
|
||||||
end?: 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;
|
next?: T;
|
||||||
prev?: 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 foreign = 'https://svelte.dev/docs#svelte_options';
|
||||||
export declare const html = "http://www.w3.org/1999/xhtml";
|
export declare const html = 'http://www.w3.org/1999/xhtml';
|
||||||
export declare const mathml = "http://www.w3.org/1998/Math/MathML";
|
export declare const mathml = 'http://www.w3.org/1998/Math/MathML';
|
||||||
export declare const svg = "http://www.w3.org/2000/svg";
|
export declare const svg = 'http://www.w3.org/2000/svg';
|
||||||
export declare const xlink = "http://www.w3.org/1999/xlink";
|
export declare const xlink = 'http://www.w3.org/1999/xlink';
|
||||||
export declare const xml = "http://www.w3.org/XML/1998/namespace";
|
export declare const xml = 'http://www.w3.org/XML/1998/namespace';
|
||||||
export declare const xmlns = "http://www.w3.org/2000/xmlns";
|
export declare const xmlns = 'http://www.w3.org/2000/xmlns';
|
||||||
export declare const valid_namespaces: string[];
|
export declare const valid_namespaces: string[];
|
||||||
export declare const namespaces: Record<string, 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];
|
const cmd = flags._[2];
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case 'dev': return 'dev';
|
case 'dev':
|
||||||
case 'build': return 'build';
|
return 'dev';
|
||||||
default: return 'help';
|
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([
|
const cmdMap = new Map([
|
||||||
['build', generate],
|
['build', generate],
|
||||||
['dev', devServer]
|
['dev', devServer],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export async function cli(args: string[]) {
|
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,
|
root: projectRoot.pathname,
|
||||||
mount: {
|
mount: {
|
||||||
[hmxRoot.pathname]: '/_hmx',
|
[hmxRoot.pathname]: '/_hmx',
|
||||||
[internalPath.pathname]: '/__hmx_internal__'
|
[internalPath.pathname]: '/__hmx_internal__',
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [['astro/snowpack-plugin', hmxPlugOptions]],
|
||||||
['astro/snowpack-plugin', hmxPlugOptions]
|
|
||||||
],
|
|
||||||
devOptions: {
|
devOptions: {
|
||||||
open: 'none',
|
open: 'none',
|
||||||
output: 'stream',
|
output: 'stream',
|
||||||
port: 0
|
port: 0,
|
||||||
},
|
},
|
||||||
packageOptions: {
|
packageOptions: {
|
||||||
knownEntrypoints: ['preact-render-to-string'],
|
knownEntrypoints: ['preact-render-to-string'],
|
||||||
external: ['@vue/server-renderer']
|
external: ['@vue/server-renderer'],
|
||||||
}
|
},
|
||||||
}, snowpackConfigPath.pathname);
|
},
|
||||||
|
snowpackConfigPath.pathname
|
||||||
|
);
|
||||||
const snowpack = await startSnowpackServer({
|
const snowpack = await startSnowpackServer({
|
||||||
config: snowpackConfig,
|
config: snowpackConfig,
|
||||||
lockfile: null
|
lockfile: null,
|
||||||
});
|
});
|
||||||
const runtime = snowpack.getServerRuntime();
|
const runtime = snowpack.getServerRuntime();
|
||||||
|
|
||||||
const server = http.createServer(async (req, res) => {
|
const server = http.createServer(async (req, res) => {
|
||||||
const fullurl = new URL(req.url || '/', 'https://example.org/');
|
const fullurl = new URL(req.url || '/', 'https://example.org/');
|
||||||
const reqPath = decodeURI(fullurl.pathname);
|
const reqPath = decodeURI(fullurl.pathname);
|
||||||
const selectedPage = (reqPath.substr(1) || 'index');
|
const selectedPage = reqPath.substr(1) || 'index';
|
||||||
console.log(reqPath, selectedPage);
|
console.log(reqPath, selectedPage);
|
||||||
|
|
||||||
const selectedPageLoc = new URL(`./pages/${selectedPage}.hmx`, hmxRoot);
|
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 HMXComponent = (props: HProps, ...children: Array<HChild>) => string;
|
||||||
export type HTag = string | HMXComponent;
|
export type HTag = string | HMXComponent;
|
||||||
|
|
||||||
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr',
|
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
||||||
'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
||||||
|
|
||||||
function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
|
function* _h(tag: string, attrs: HProps, children: Array<HChild>) {
|
||||||
yield `<${tag}`;
|
yield `<${tag}`;
|
||||||
|
|
|
@ -7,11 +7,11 @@ export function __vue_static(VueComponent: Component) {
|
||||||
return async (attrs: Record<string, any>, ...children: any): Promise<string> => {
|
return async (attrs: Record<string, any>, ...children: any): Promise<string> => {
|
||||||
const app = createSSRApp({
|
const app = createSSRApp({
|
||||||
components: {
|
components: {
|
||||||
VueComponent
|
VueComponent,
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
return createElement(VueComponent as any, attrs);
|
return createElement(VueComponent as any, attrs);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const html = await renderToString(app);
|
const html = await renderToString(app);
|
||||||
|
|
|
@ -24,15 +24,16 @@ export default async function(astroConfig: AstroConfig) {
|
||||||
const dist = new URL(astroConfig.dist + '/', projectRoot);
|
const dist = new URL(astroConfig.dist + '/', projectRoot);
|
||||||
|
|
||||||
const configPath = new URL('./snowpack.config.js', projectRoot).pathname;
|
const configPath = new URL('./snowpack.config.js', projectRoot).pathname;
|
||||||
const config = await loadConfiguration({
|
const config = await loadConfiguration(
|
||||||
|
{
|
||||||
root: projectRoot.pathname,
|
root: projectRoot.pathname,
|
||||||
devOptions:
|
devOptions: { open: 'none', output: 'stream' },
|
||||||
{open: 'none', output: 'stream'
|
},
|
||||||
}
|
configPath
|
||||||
}, configPath);
|
);
|
||||||
const snowpack = await startSnowpackServer({
|
const snowpack = await startSnowpackServer({
|
||||||
config,
|
config,
|
||||||
lockfile: null // TODO should this be required?
|
lockfile: null, // TODO should this be required?
|
||||||
});
|
});
|
||||||
|
|
||||||
const runtime = snowpack.getServerRuntime();
|
const runtime = snowpack.getServerRuntime();
|
||||||
|
|
|
@ -6,14 +6,14 @@ const characterReferences = {
|
||||||
'<': 'lt',
|
'<': 'lt',
|
||||||
'>': 'gt',
|
'>': 'gt',
|
||||||
'{': 'lbrace',
|
'{': 'lbrace',
|
||||||
'}': 'rbrace'
|
'}': 'rbrace',
|
||||||
};
|
};
|
||||||
|
|
||||||
type EncodedChars = '"' | '&' | '<' | '>' | '{' | '}';
|
type EncodedChars = '"' | '&' | '<' | '>' | '{' | '}';
|
||||||
|
|
||||||
function encode(value: string): string {
|
function encode(value: string): string {
|
||||||
return value.replace(/["&<>{}]/g, (raw: 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: {
|
exit: {
|
||||||
codeFlowValue() {
|
codeFlowValue() {
|
||||||
const token: Token = arguments[0];
|
const token: Token = arguments[0];
|
||||||
const serialize = this.sliceSerialize as unknown as (t: Token) => string;
|
const serialize = (this.sliceSerialize as unknown) as (t: Token) => string;
|
||||||
const raw = this.raw as unknown as (s: string) => void;
|
const raw = (this.raw as unknown) as (s: string) => void;
|
||||||
const value = serialize(token);
|
const value = serialize(token);
|
||||||
raw(encode(value));
|
raw(encode(value));
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export { plugin as default };
|
||||||
plugin as default
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,15 +1,6 @@
|
||||||
const [
|
const [CHARS, TAG_START, TAG_END, END_TAG_START, EQ, EOF, UNKNOWN] = Array.from(new Array(20), (x, i) => i + 1);
|
||||||
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',
|
const voidTags = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
||||||
'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
||||||
|
|
||||||
type Visitor = (tag: Tag) => Tag;
|
type Visitor = (tag: Tag) => Tag;
|
||||||
|
|
||||||
|
@ -71,7 +62,7 @@ function createState(code: string, visitor: Visitor): State {
|
||||||
return {
|
return {
|
||||||
code,
|
code,
|
||||||
index: 0,
|
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) {
|
function replaceTag(state: State, tag: Tag) {
|
||||||
|
@ -170,7 +161,7 @@ function consumeText(state: State): Text {
|
||||||
type: 0,
|
type: 0,
|
||||||
data,
|
data,
|
||||||
start,
|
start,
|
||||||
end: state.index - 1
|
end: state.index - 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +177,8 @@ function consumeTagName(state: State): string {
|
||||||
|
|
||||||
function consumeAttribute(state: State): Attribute {
|
function consumeAttribute(state: State): Attribute {
|
||||||
let start = state.index;
|
let start = state.index;
|
||||||
let name = '', token;
|
let name = '',
|
||||||
|
token;
|
||||||
do {
|
do {
|
||||||
name += stateChar(state).toLowerCase();
|
name += stateChar(state).toLowerCase();
|
||||||
token = consumeToken(state);
|
token = consumeToken(state);
|
||||||
|
@ -198,7 +190,7 @@ function consumeAttribute(state: State): Attribute {
|
||||||
name,
|
name,
|
||||||
boolean: true,
|
boolean: true,
|
||||||
start,
|
start,
|
||||||
end: state.index - 1
|
end: state.index - 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +205,7 @@ function consumeAttribute(state: State): Attribute {
|
||||||
value,
|
value,
|
||||||
boolean: false,
|
boolean: false,
|
||||||
start,
|
start,
|
||||||
end: state.index - 1
|
end: state.index - 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +271,7 @@ function consumeTag(state: State): Tag {
|
||||||
children,
|
children,
|
||||||
void: voidTags.has(tagName),
|
void: voidTags.has(tagName),
|
||||||
start,
|
start,
|
||||||
end: state.index - 1
|
end: state.index - 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const replacement = state.visitor(node);
|
const replacement = state.visitor(node);
|
||||||
|
@ -294,7 +286,7 @@ function consumeDocument(state: State): Document {
|
||||||
const children: Array<Tag | Text> = consumeChildren(state);
|
const children: Array<Tag | Text> = consumeChildren(state);
|
||||||
|
|
||||||
return {
|
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 path from 'path';
|
||||||
import astring from "astring";
|
import astring from 'astring';
|
||||||
import esbuild from "esbuild";
|
import esbuild from 'esbuild';
|
||||||
import eslexer from "es-module-lexer";
|
import eslexer from 'es-module-lexer';
|
||||||
import micromark from "micromark";
|
import micromark from 'micromark';
|
||||||
import gfmSyntax from "micromark-extension-gfm";
|
import gfmSyntax from 'micromark-extension-gfm';
|
||||||
import matter from "gray-matter";
|
import matter from 'gray-matter';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import gfmHtml from "micromark-extension-gfm/html.js";
|
import gfmHtml from 'micromark-extension-gfm/html.js';
|
||||||
import { walk, parse } from "./compiler.js";
|
import { walk, parse } from './compiler.js';
|
||||||
import markdownEncode from './markdown-encode.js';
|
import markdownEncode from './markdown-encode.js';
|
||||||
import { preparse } from './parser.js';
|
import { preparse } from './parser.js';
|
||||||
|
|
||||||
|
@ -18,18 +18,20 @@ const { transformSync } = esbuild;
|
||||||
interface Attribute {
|
interface Attribute {
|
||||||
start: 574;
|
start: 574;
|
||||||
end: 595;
|
end: 595;
|
||||||
type: "Attribute";
|
type: 'Attribute';
|
||||||
name: "class";
|
name: 'class';
|
||||||
value: any;
|
value: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CompileOptions {
|
interface CompileOptions {
|
||||||
resolve: (p: string) => string
|
resolve: (p: string) => string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultCompileOptions: CompileOptions = {
|
const defaultCompileOptions: CompileOptions = {
|
||||||
resolve(p: string) { return p; }
|
resolve(p: string) {
|
||||||
}
|
return p;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
function internalImport(internalPath: string) {
|
function internalImport(internalPath: string) {
|
||||||
return `/__hmx_internal__/${internalPath}`;
|
return `/__hmx_internal__/${internalPath}`;
|
||||||
|
@ -47,7 +49,7 @@ function getAttributes(attrs: Attribute[]): Record<string, string> {
|
||||||
}
|
}
|
||||||
if (attr.value.length > 1) {
|
if (attr.value.length > 1) {
|
||||||
result[attr.name] =
|
result[attr.name] =
|
||||||
"(" +
|
'(' +
|
||||||
attr.value
|
attr.value
|
||||||
.map((v: TemplateNode) => {
|
.map((v: TemplateNode) => {
|
||||||
if (v.expression) {
|
if (v.expression) {
|
||||||
|
@ -56,21 +58,21 @@ function getAttributes(attrs: Attribute[]): Record<string, string> {
|
||||||
return JSON.stringify(getTextFromAttribute(v));
|
return JSON.stringify(getTextFromAttribute(v));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.join("+") +
|
.join('+') +
|
||||||
")";
|
')';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const val: TemplateNode = attr.value[0];
|
const val: TemplateNode = attr.value[0];
|
||||||
switch (val.type) {
|
switch (val.type) {
|
||||||
case "MustacheTag":
|
case 'MustacheTag':
|
||||||
result[attr.name] = "(" + val.expression + ")";
|
result[attr.name] = '(' + val.expression + ')';
|
||||||
continue;
|
continue;
|
||||||
case "Text":
|
case 'Text':
|
||||||
result[attr.name] = JSON.stringify(getTextFromAttribute(val));
|
result[attr.name] = JSON.stringify(getTextFromAttribute(val));
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
console.log(val);
|
console.log(val);
|
||||||
throw new Error("UNKNOWN V");
|
throw new Error('UNKNOWN V');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -84,23 +86,19 @@ function getTextFromAttribute(attr: any): string {
|
||||||
return attr.data;
|
return attr.data;
|
||||||
}
|
}
|
||||||
console.log(attr);
|
console.log(attr);
|
||||||
throw new Error("UNKNOWN attr");
|
throw new Error('UNKNOWN attr');
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateAttributes(attrs: Record<string, string>): string {
|
function generateAttributes(attrs: Record<string, string>): string {
|
||||||
let result: string = "{";
|
let result: string = '{';
|
||||||
for (const [key, val] of Object.entries(attrs)) {
|
for (const [key, val] of Object.entries(attrs)) {
|
||||||
result += JSON.stringify(key) + ":" + val + ",";
|
result += JSON.stringify(key) + ':' + val + ',';
|
||||||
}
|
}
|
||||||
return result + "}";
|
return result + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getComponentWrapper(
|
function getComponentWrapper(_name: string, { type, url }: { type: string; url: string }, { resolve }: CompileOptions) {
|
||||||
_name: string,
|
const [name, kind] = _name.split(':');
|
||||||
{ type, url }: { type: string; url: string },
|
|
||||||
{ resolve }: CompileOptions
|
|
||||||
) {
|
|
||||||
const [name, kind] = _name.split(":");
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case '.hmx': {
|
case '.hmx': {
|
||||||
if (kind) {
|
if (kind) {
|
||||||
|
@ -112,11 +110,9 @@ function getComponentWrapper(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case '.jsx': {
|
case '.jsx': {
|
||||||
if (kind === "dynamic") {
|
if (kind === 'dynamic') {
|
||||||
return {
|
return {
|
||||||
wrapper: `__preact_dynamic(${name}, new URL(${JSON.stringify(
|
wrapper: `__preact_dynamic(${name}, new URL(${JSON.stringify(url.replace(/\.[^.]+$/, '.js'))}, \`http://TEST\${import.meta.url}\`).pathname, '${resolve('preact')}')`,
|
||||||
url.replace(/\.[^.]+$/, ".js")
|
|
||||||
)}, \`http://TEST\${import.meta.url}\`).pathname, '${resolve('preact')}')`,
|
|
||||||
wrapperImport: `import {__preact_dynamic} from '${internalImport('render/preact.js')}';`,
|
wrapperImport: `import {__preact_dynamic} from '${internalImport('render/preact.js')}';`,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
@ -127,26 +123,22 @@ function getComponentWrapper(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case '.svelte': {
|
case '.svelte': {
|
||||||
if(kind === "dynamic") {
|
if (kind === 'dynamic') {
|
||||||
return {
|
return {
|
||||||
wrapper: `__svelte_dynamic(${name}, new URL(${JSON.stringify(
|
wrapper: `__svelte_dynamic(${name}, new URL(${JSON.stringify(url.replace(/\.[^.]+$/, '.svelte.js'))}, \`http://TEST\${import.meta.url}\`).pathname)`,
|
||||||
url.replace(/\.[^.]+$/, ".svelte.js")
|
|
||||||
)}, \`http://TEST\${import.meta.url}\`).pathname)`,
|
|
||||||
wrapperImport: `import {__svelte_dynamic} from '${internalImport('render/svelte.js')}';`,
|
wrapperImport: `import {__svelte_dynamic} from '${internalImport('render/svelte.js')}';`,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
wrapper: `__svelte_static(${name})`,
|
wrapper: `__svelte_static(${name})`,
|
||||||
wrapperImport: `import {__svelte_static} from '${internalImport('render/svelte.js')}';`
|
wrapperImport: `import {__svelte_static} from '${internalImport('render/svelte.js')}';`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case '.vue': {
|
case '.vue': {
|
||||||
if(kind === "dynamic") {
|
if (kind === 'dynamic') {
|
||||||
return {
|
return {
|
||||||
wrapper: `__vue_dynamic(${name}, new URL(${JSON.stringify(
|
wrapper: `__vue_dynamic(${name}, new URL(${JSON.stringify(url.replace(/\.[^.]+$/, '.vue.js'))}, \`http://TEST\${import.meta.url}\`).pathname, '${resolve('vue')}')`,
|
||||||
url.replace(/\.[^.]+$/, ".vue.js")
|
|
||||||
)}, \`http://TEST\${import.meta.url}\`).pathname, '${resolve('vue')}')`,
|
|
||||||
wrapperImport: `import {__vue_dynamic} from '${internalImport('render/vue.js')}';`,
|
wrapperImport: `import {__vue_dynamic} from '${internalImport('render/vue.js')}';`,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
@ -154,16 +146,16 @@ function getComponentWrapper(
|
||||||
wrapper: `__vue_static(${name})`,
|
wrapper: `__vue_static(${name})`,
|
||||||
wrapperImport: `
|
wrapperImport: `
|
||||||
import {__vue_static} from '${internalImport('render/vue.js')}';
|
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 {
|
function runPreparser(template: string): string {
|
||||||
const doc = preparse(template, tag => {
|
const doc = preparse(template, (tag) => {
|
||||||
if (tag.tagName === 'script') {
|
if (tag.tagName === 'script') {
|
||||||
let isSetup = false;
|
let isSetup = false;
|
||||||
for (let attr of tag.attributes) {
|
for (let attr of tag.attributes) {
|
||||||
|
@ -177,19 +169,21 @@ function runPreparser(template: string): string {
|
||||||
|
|
||||||
const content = tag.children[0];
|
const content = tag.children[0];
|
||||||
let { code } = transformSync(content, {
|
let { code } = transformSync(content, {
|
||||||
loader: "tsx",
|
loader: 'tsx',
|
||||||
jsxFactory: "h",
|
jsxFactory: 'h',
|
||||||
jsxFragment: "Fragment",
|
jsxFragment: 'Fragment',
|
||||||
charset: "utf8",
|
charset: 'utf8',
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...tag,
|
...tag,
|
||||||
children: [{
|
children: [
|
||||||
|
{
|
||||||
type: 0,
|
type: 0,
|
||||||
data: code,
|
data: code,
|
||||||
start: 0,
|
start: 0,
|
||||||
end: 0
|
end: 0,
|
||||||
}]
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,9 +203,9 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions)
|
||||||
|
|
||||||
const ast = parse(template, {});
|
const ast = parse(template, {});
|
||||||
// Todo: Validate that `h` and `Fragment` aren't defined in the script
|
// 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(
|
const components = Object.fromEntries(
|
||||||
scriptImports.map((imp) => {
|
scriptImports.map((imp) => {
|
||||||
const componentType = path.posix.extname(imp.n!);
|
const componentType = path.posix.extname(imp.n!);
|
||||||
|
@ -222,7 +216,7 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions)
|
||||||
|
|
||||||
const additionalImports = new Set<string>();
|
const additionalImports = new Set<string>();
|
||||||
let items: { name: string; jsx: 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 collectionItem: { name: string; jsx: string } | undefined;
|
||||||
let currentItemName: string | undefined;
|
let currentItemName: string | undefined;
|
||||||
let currentDepth = 0;
|
let currentDepth = 0;
|
||||||
|
@ -232,12 +226,12 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions)
|
||||||
enter(node: TemplateNode, parent, prop, index) {
|
enter(node: TemplateNode, parent, prop, index) {
|
||||||
// console.log("enter", node.type);
|
// console.log("enter", node.type);
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
case "MustacheTag":
|
case 'MustacheTag':
|
||||||
let { code } = transformSync(node.expression, {
|
let { code } = transformSync(node.expression, {
|
||||||
loader: "jsx",
|
loader: 'jsx',
|
||||||
jsxFactory: "h",
|
jsxFactory: 'h',
|
||||||
jsxFragment: "Fragment",
|
jsxFragment: 'Fragment',
|
||||||
charset: "utf8",
|
charset: 'utf8',
|
||||||
});
|
});
|
||||||
|
|
||||||
let matches: RegExpExecArray[] = [];
|
let matches: RegExpExecArray[] = [];
|
||||||
|
@ -249,142 +243,127 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions)
|
||||||
}
|
}
|
||||||
for (const match of matches.reverse()) {
|
for (const match of matches.reverse()) {
|
||||||
const name = match[1];
|
const name = match[1];
|
||||||
const [componentName, componentKind] = name.split(":");
|
const [componentName, componentKind] = name.split(':');
|
||||||
if (!components[componentName]) {
|
if (!components[componentName]) {
|
||||||
throw new Error(`Unknown Component: ${componentName}`);
|
throw new Error(`Unknown Component: ${componentName}`);
|
||||||
}
|
}
|
||||||
const { wrapper, wrapperImport } = getComponentWrapper(
|
const { wrapper, wrapperImport } = getComponentWrapper(name, components[componentName], compileOptions);
|
||||||
name,
|
|
||||||
components[componentName],
|
|
||||||
compileOptions
|
|
||||||
);
|
|
||||||
if (wrapperImport) {
|
if (wrapperImport) {
|
||||||
additionalImports.add(wrapperImport);
|
additionalImports.add(wrapperImport);
|
||||||
}
|
}
|
||||||
if (wrapper !== name) {
|
if (wrapper !== name) {
|
||||||
code =
|
code = code.slice(0, match.index + 2) + wrapper + code.slice(match.index + match[0].length - 1);
|
||||||
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;
|
return;
|
||||||
case "Slot":
|
case 'Slot':
|
||||||
mode = "SLOT";
|
mode = 'SLOT';
|
||||||
collectionItem!.jsx += `,child`;
|
collectionItem!.jsx += `,child`;
|
||||||
return;
|
return;
|
||||||
case "Comment":
|
case 'Comment':
|
||||||
return;
|
return;
|
||||||
case "Fragment":
|
case 'Fragment':
|
||||||
// Ignore if its the top level fragment
|
// Ignore if its the top level fragment
|
||||||
// This should be cleaned up, but right now this is how the old thing worked
|
// This should be cleaned up, but right now this is how the old thing worked
|
||||||
if (!collectionItem) {
|
if (!collectionItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "InlineComponent":
|
case 'InlineComponent':
|
||||||
case "Element":
|
case 'Element':
|
||||||
const name: string = node.name;
|
const name: string = node.name;
|
||||||
if (!name) {
|
if (!name) {
|
||||||
console.log(node);
|
console.log(node);
|
||||||
throw new Error("AHHHH");
|
throw new Error('AHHHH');
|
||||||
}
|
}
|
||||||
const attributes = getAttributes(node.attributes);
|
const attributes = getAttributes(node.attributes);
|
||||||
currentDepth++;
|
currentDepth++;
|
||||||
currentItemName = name;
|
currentItemName = name;
|
||||||
if (!collectionItem) {
|
if (!collectionItem) {
|
||||||
collectionItem = { name, jsx: "" };
|
collectionItem = { name, jsx: '' };
|
||||||
items.push(collectionItem);
|
items.push(collectionItem);
|
||||||
}
|
}
|
||||||
collectionItem.jsx += collectionItem.jsx === "" ? "" : ",";
|
collectionItem.jsx += collectionItem.jsx === '' ? '' : ',';
|
||||||
const COMPONENT_NAME_SCANNER = /^[A-Z]/;
|
const COMPONENT_NAME_SCANNER = /^[A-Z]/;
|
||||||
if (!COMPONENT_NAME_SCANNER.test(name)) {
|
if (!COMPONENT_NAME_SCANNER.test(name)) {
|
||||||
collectionItem.jsx += `h("${name}", ${
|
collectionItem.jsx += `h("${name}", ${attributes ? generateAttributes(attributes) : 'null'}`;
|
||||||
attributes ? generateAttributes(attributes) : "null"
|
|
||||||
}`;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (name === 'Component') {
|
if (name === 'Component') {
|
||||||
collectionItem.jsx += `h(Fragment, null`;
|
collectionItem.jsx += `h(Fragment, null`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [componentName, componentKind] = name.split(":");
|
const [componentName, componentKind] = name.split(':');
|
||||||
const componentImportData = components[componentName];
|
const componentImportData = components[componentName];
|
||||||
if (!componentImportData) {
|
if (!componentImportData) {
|
||||||
throw new Error(`Unknown Component: ${componentName}`);
|
throw new Error(`Unknown Component: ${componentName}`);
|
||||||
}
|
}
|
||||||
const { wrapper, wrapperImport } = getComponentWrapper(
|
const { wrapper, wrapperImport } = getComponentWrapper(name, components[componentName], compileOptions);
|
||||||
name,
|
|
||||||
components[componentName],
|
|
||||||
compileOptions
|
|
||||||
);
|
|
||||||
if (wrapperImport) {
|
if (wrapperImport) {
|
||||||
additionalImports.add(wrapperImport);
|
additionalImports.add(wrapperImport);
|
||||||
}
|
}
|
||||||
collectionItem.jsx += `h(${wrapper}, ${
|
collectionItem.jsx += `h(${wrapper}, ${attributes ? generateAttributes(attributes) : 'null'}`;
|
||||||
attributes ? generateAttributes(attributes) : "null"
|
|
||||||
}`;
|
|
||||||
return;
|
return;
|
||||||
case "Attribute": {
|
case 'Attribute': {
|
||||||
this.skip();
|
this.skip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "Text": {
|
case 'Text': {
|
||||||
const text = getTextFromAttribute(node);
|
const text = getTextFromAttribute(node);
|
||||||
if (mode === "SLOT") {
|
if (mode === 'SLOT') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!text.trim()) {
|
if (!text.trim()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!collectionItem) {
|
if (!collectionItem) {
|
||||||
throw new Error("Not possible! TEXT:" + text);
|
throw new Error('Not possible! TEXT:' + text);
|
||||||
}
|
}
|
||||||
if (currentItemName === "script" || currentItemName === "code") {
|
if (currentItemName === 'script' || currentItemName === 'code') {
|
||||||
collectionItem.jsx += "," + JSON.stringify(text);
|
collectionItem.jsx += ',' + JSON.stringify(text);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
collectionItem.jsx += "," + JSON.stringify(text);
|
collectionItem.jsx += ',' + JSON.stringify(text);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
console.log(node);
|
console.log(node);
|
||||||
throw new Error("Unexpected node type: " + node.type);
|
throw new Error('Unexpected node type: ' + node.type);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
leave(node: TemplateNode, parent, prop, index) {
|
leave(node: TemplateNode, parent, prop, index) {
|
||||||
// console.log("leave", node.type);
|
// console.log("leave", node.type);
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
case "Text":
|
case 'Text':
|
||||||
case "MustacheTag":
|
case 'MustacheTag':
|
||||||
case "Attribute":
|
case 'Attribute':
|
||||||
case "Comment":
|
case 'Comment':
|
||||||
return;
|
return;
|
||||||
case "Slot": {
|
case 'Slot': {
|
||||||
const name = node.name;
|
const name = node.name;
|
||||||
if (name === "slot") {
|
if (name === 'slot') {
|
||||||
mode = "JSX";
|
mode = 'JSX';
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "Fragment":
|
case 'Fragment':
|
||||||
if (!collectionItem) {
|
if (!collectionItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "Element":
|
case 'Element':
|
||||||
case "InlineComponent":
|
case 'InlineComponent':
|
||||||
if (!collectionItem) {
|
if (!collectionItem) {
|
||||||
throw new Error("Not possible! CLOSE " + node.name);
|
throw new Error('Not possible! CLOSE ' + node.name);
|
||||||
}
|
}
|
||||||
collectionItem.jsx += ")";
|
collectionItem.jsx += ')';
|
||||||
currentDepth--;
|
currentDepth--;
|
||||||
if (currentDepth === 0) {
|
if (currentDepth === 0) {
|
||||||
collectionItem = undefined;
|
collectionItem = undefined;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
default:
|
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 {
|
return {
|
||||||
script: script + "\n" + Array.from(additionalImports).join("\n"),
|
script: script + '\n' + Array.from(additionalImports).join('\n'),
|
||||||
items,
|
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)};
|
return ${JSON.stringify(setupData)};
|
||||||
}</script><head></head><body>${mdHtml}</body>`, compileOptions);
|
}</script><head></head><body>${mdHtml}</body>`,
|
||||||
|
compileOptions
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function transformFromSource(
|
async function transformFromSource(contents: string, filename: string, compileOptions: CompileOptions): Promise<ReturnType<typeof convertHmxToJsx>> {
|
||||||
contents: string,
|
|
||||||
filename: string,
|
|
||||||
compileOptions: CompileOptions
|
|
||||||
): Promise<ReturnType<typeof convertHmxToJsx>> {
|
|
||||||
switch (path.extname(filename)) {
|
switch (path.extname(filename)) {
|
||||||
case ".hmx":
|
case '.hmx':
|
||||||
return convertHmxToJsx(contents, compileOptions);
|
return convertHmxToJsx(contents, compileOptions);
|
||||||
case ".md":
|
case '.md':
|
||||||
return convertMdToJsx(contents, compileOptions);
|
return convertMdToJsx(contents, compileOptions);
|
||||||
default:
|
default:
|
||||||
throw new Error("Not Supported!");
|
throw new Error('Not Supported!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function compilePage(source: string, filename: string, opts: CompileOptions = defaultCompileOptions) {
|
export async function compilePage(source: string, filename: string, opts: CompileOptions = defaultCompileOptions) {
|
||||||
const sourceJsx = await transformFromSource(source, filename, opts);
|
const sourceJsx = await transformFromSource(source, filename, opts);
|
||||||
const headItem = sourceJsx.items.find((item) => item.name === "head");
|
const headItem = sourceJsx.items.find((item) => item.name === 'head');
|
||||||
const bodyItem = sourceJsx.items.find((item) => item.name === "body");
|
const bodyItem = sourceJsx.items.find((item) => item.name === 'body');
|
||||||
const headItemJsx = !headItem
|
const headItemJsx = !headItem ? 'null' : headItem.jsx.replace('"head"', 'isRoot ? "head" : Fragment');
|
||||||
? "null"
|
const bodyItemJsx = !bodyItem ? 'null' : bodyItem.jsx.replace('"head"', 'isRoot ? "body" : Fragment');
|
||||||
: headItem.jsx.replace('"head"', 'isRoot ? "head" : Fragment');
|
|
||||||
const bodyItemJsx = !bodyItem
|
|
||||||
? "null"
|
|
||||||
: bodyItem.jsx.replace('"head"', 'isRoot ? "body" : Fragment');
|
|
||||||
|
|
||||||
const modJsx = `
|
const modJsx = `
|
||||||
${sourceJsx.script}
|
${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) {
|
export async function compileComponent(source: string, filename: string, opts: CompileOptions = defaultCompileOptions) {
|
||||||
const sourceJsx = await transformFromSource(source, filename, opts);
|
const sourceJsx = await transformFromSource(source, filename, opts);
|
||||||
const componentJsx = sourceJsx.items.find(
|
const componentJsx = sourceJsx.items.find((item) => item.name === 'Component');
|
||||||
(item) => item.name === "Component"
|
|
||||||
);
|
|
||||||
if (!componentJsx) {
|
if (!componentJsx) {
|
||||||
throw new Error(`${filename} <Component> expected!`);
|
throw new Error(`${filename} <Component> expected!`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue