@marko/language-tools 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extractors/script/index.d.ts +19 -0
- package/dist/extractors/script/util/attach-scopes.d.ts +60 -0
- package/dist/extractors/script/util/is-valid-identifier.d.ts +1 -0
- package/dist/extractors/script/util/jsdoc-input-type.d.ts +9 -0
- package/dist/extractors/script/util/runtime-overrides.d.ts +1 -0
- package/dist/extractors/script/util/script-parser.d.ts +7 -0
- package/dist/extractors/style/index.d.ts +11 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2842 -0
- package/dist/index.mjs +2808 -0
- package/dist/parser.d.ts +227 -0
- package/dist/util/extractor.d.ts +28 -0
- package/dist/util/get-node-at-offset.d.ts +2 -0
- package/marko.internal.d.ts +520 -0
- package/package.json +56 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type TS from "typescript/lib/tsserverlibrary";
|
|
2
|
+
import type { TaglibLookup } from "@marko/babel-utils";
|
|
3
|
+
import { type Parsed } from "../../parser";
|
|
4
|
+
/**
|
|
5
|
+
* Iterate over the Marko CST and extract all the script content.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum ScriptLang {
|
|
8
|
+
js = "js",
|
|
9
|
+
ts = "ts"
|
|
10
|
+
}
|
|
11
|
+
export interface ExtractScriptOptions {
|
|
12
|
+
ts?: typeof TS;
|
|
13
|
+
parsed: Parsed;
|
|
14
|
+
lookup: TaglibLookup;
|
|
15
|
+
scriptLang: ScriptLang;
|
|
16
|
+
runtimeTypesCode?: string;
|
|
17
|
+
componentFilename?: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
export declare function extractScript(opts: ExtractScriptOptions): import("../../util/extractor").Extracted;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type Node, Parsed, Repeatable, Repeated } from "../../../parser";
|
|
2
|
+
import type { ScriptParser } from "./script-parser";
|
|
3
|
+
export interface Options {
|
|
4
|
+
parsed: Parsed;
|
|
5
|
+
scriptParser: ScriptParser;
|
|
6
|
+
}
|
|
7
|
+
export type Scope = ProgramScope | TagScope;
|
|
8
|
+
export interface ProgramScope {
|
|
9
|
+
parent: undefined;
|
|
10
|
+
hoists: false;
|
|
11
|
+
bindings: Bindings;
|
|
12
|
+
}
|
|
13
|
+
export interface TagScope {
|
|
14
|
+
parent: Scope;
|
|
15
|
+
hoists: boolean;
|
|
16
|
+
bindings: undefined | Bindings;
|
|
17
|
+
}
|
|
18
|
+
export type Binding = VarBinding | ParamBinding | HoistedBinding;
|
|
19
|
+
export interface VarBinding {
|
|
20
|
+
type: BindingType.var;
|
|
21
|
+
name: string;
|
|
22
|
+
node: Node.ParentNode;
|
|
23
|
+
scope: Scope;
|
|
24
|
+
hoisted: boolean;
|
|
25
|
+
mutated: boolean;
|
|
26
|
+
sourceName: string | undefined;
|
|
27
|
+
objectPath: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
export interface ParamBinding {
|
|
30
|
+
type: BindingType.param;
|
|
31
|
+
name: string;
|
|
32
|
+
node: Node.ParentNode;
|
|
33
|
+
scope: TagScope;
|
|
34
|
+
hoisted: false;
|
|
35
|
+
}
|
|
36
|
+
export interface HoistedBinding {
|
|
37
|
+
type: BindingType.hoisted;
|
|
38
|
+
scope: Scope;
|
|
39
|
+
bindings: Repeated<VarBinding>;
|
|
40
|
+
hoisted: false;
|
|
41
|
+
}
|
|
42
|
+
export declare enum BindingType {
|
|
43
|
+
var = 0,
|
|
44
|
+
param = 1,
|
|
45
|
+
hoisted = 2
|
|
46
|
+
}
|
|
47
|
+
type Bindings = {
|
|
48
|
+
[name: string]: Binding;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Traverses the Marko tree and analyzes the bindings.
|
|
52
|
+
*/
|
|
53
|
+
export declare function crawlProgramScope(parsed: Parsed, scriptParser: ScriptParser): [number, ...number[]] | [...number[], number] | undefined;
|
|
54
|
+
export declare function getHoists(node: Node.Program): Repeatable<string>;
|
|
55
|
+
export declare function getHoistSources(node: Node.ParentNode): Repeatable<string>;
|
|
56
|
+
export declare function getMutatedVars(node: Node.ParentNode): Repeatable<VarBinding>;
|
|
57
|
+
export declare function isMutatedVar(node: Node.ParentNode, name: string): boolean;
|
|
58
|
+
export declare function hasHoists(node: Node.ParentTag): boolean;
|
|
59
|
+
export declare function getBoundAttrMemberExpressionStartOffset(value: Node.AttrValue): number | undefined;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isValidIdentifier(name: string): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type TS from "typescript";
|
|
2
|
+
import type { Repeatable } from "../../../parser";
|
|
3
|
+
export default function getJSDocInputType(comment: string, ts: typeof TS): {
|
|
4
|
+
typeParameters: Repeatable<{
|
|
5
|
+
name: string;
|
|
6
|
+
constraint: undefined | string;
|
|
7
|
+
default: undefined | string;
|
|
8
|
+
}>;
|
|
9
|
+
} | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getRuntimeOverrides(runtimeTypes: string, generics: string, applyGenerics: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type * as t from "@babel/types";
|
|
2
|
+
export declare class ScriptParser {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(sourceFileName: string, code: string);
|
|
5
|
+
statementAt<T = t.Statement[]>(offset: number, src: string): never[] | (T extends unknown[] ? T : readonly [T]);
|
|
6
|
+
expressionAt<T = t.Expression>(offset: number, src: string): T | undefined;
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TaglibLookup } from "@marko/babel-utils";
|
|
2
|
+
import { type Parsed } from "../../parser";
|
|
3
|
+
import { type Extracted } from "../../util/extractor";
|
|
4
|
+
export interface ExtractStyleOptions {
|
|
5
|
+
parsed: Parsed;
|
|
6
|
+
lookup: TaglibLookup;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Iterate over the Marko CST and extract all the stylesheets.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractStyle(opts: ExtractStyleOptions): Map<string, Extracted>;
|
package/dist/index.d.ts
ADDED