@markw65/monkeyc-optimizer 1.0.38 → 1.0.40
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/README.md +53 -0
- package/build/api.cjs +645 -186
- package/build/optimizer.cjs +476 -6950
- package/build/sdk-util.cjs +212 -7146
- package/build/src/api.d.ts +13 -4
- package/build/src/inliner.d.ts +2 -2
- package/build/src/jungles.d.ts +5 -1
- package/build/src/launch.d.ts +2 -2
- package/build/src/manifest.d.ts +2 -63
- package/build/src/mc-rewrite.d.ts +4 -2
- package/build/src/optimizer-types.d.ts +16 -7
- package/build/src/optimizer.d.ts +16 -3
- package/build/src/projects.d.ts +2 -0
- package/build/src/resources.d.ts +5 -0
- package/build/src/sdk-util.d.ts +5 -1
- package/build/src/visitor.d.ts +1 -0
- package/build/src/xml-util.d.ts +140 -0
- package/build/util.cjs +1491 -1565
- package/package.json +10 -11
package/build/src/api.d.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { hasProperty, traverseAst } from "./ast";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { JungleResourceMap } from "./jungles";
|
|
4
|
+
import { FunctionInfo, FunctionStateNode, LookupDefinition, ModuleStateNode, ProgramState, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl } from "./optimizer-types";
|
|
5
|
+
export { visitorNode, visitReferences } from "./visitor";
|
|
5
6
|
export { traverseAst, hasProperty };
|
|
6
|
-
export declare function
|
|
7
|
+
export declare function parseSdkVersion(version: string | undefined): number;
|
|
8
|
+
export declare function checkCompilerVersion(version: string, sdkVer: number): boolean | undefined;
|
|
9
|
+
export declare function getApiMapping(state?: ProgramState, resourcesMap?: Record<string, JungleResourceMap>): Promise<ProgramStateNode | null>;
|
|
7
10
|
export declare function isStateNode(node: StateNodeDecl): node is StateNode;
|
|
8
11
|
export declare function variableDeclarationName(node: mctree.TypedIdentifier | mctree.InstanceofIdentifier): string;
|
|
9
12
|
export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
|
|
10
13
|
export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
|
|
11
14
|
export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
|
|
12
15
|
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null, options?: Record<string, unknown> | null): string;
|
|
13
|
-
export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier
|
|
16
|
+
export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier): ModuleStateNode | {
|
|
17
|
+
name: string;
|
|
18
|
+
decls: {
|
|
19
|
+
parent: StateNode;
|
|
20
|
+
results: StateNodeDecl[];
|
|
21
|
+
};
|
|
22
|
+
}[] | null;
|
|
14
23
|
export declare function getApiFunctionInfo(func: FunctionStateNode): FunctionInfo;
|
|
15
24
|
export declare function markInvokeClassMethod(func: FunctionStateNode): void;
|
package/build/src/inliner.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { FunctionStateNode, ProgramStateAnalysis, ProgramStateLive } from "./opt
|
|
|
3
3
|
export declare function inlinableSubExpression(expr: mctree.Expression): mctree.SimpleCallExpression | null;
|
|
4
4
|
export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): boolean;
|
|
5
5
|
declare type InlineBody = mctree.BlockStatement | mctree.ExpressionStatement["expression"];
|
|
6
|
-
export declare function unused(expression: mctree.ExpressionStatement["expression"]): mctree.Statement[];
|
|
7
|
-
export declare function unused(expression: mctree.ExpressionStatement["expression"], top: true): mctree.Statement[] | null;
|
|
6
|
+
export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"]): mctree.Statement[];
|
|
7
|
+
export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"], top: true): mctree.Statement[] | null;
|
|
8
8
|
export declare function diagnostic(state: ProgramStateLive, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
|
|
9
9
|
export declare type InlineContext = mctree.ReturnStatement | mctree.IfStatement | mctree.AssignmentExpression | mctree.ExpressionStatement | mctree.VariableDeclarator;
|
|
10
10
|
export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
|
package/build/src/jungles.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ManifestXML } from "./manifest";
|
|
2
2
|
import { BuildConfig } from "./optimizer-types.js";
|
|
3
|
+
import { xmlUtil } from "./sdk-util";
|
|
3
4
|
export declare type Target = {
|
|
4
5
|
product: string;
|
|
5
6
|
qualifier: JungleQualifier;
|
|
@@ -35,18 +36,21 @@ export declare type JungleQualifier = {
|
|
|
35
36
|
annotations?: BarrelAnnotations;
|
|
36
37
|
barrelMap?: BarrelMap;
|
|
37
38
|
optBarrels?: OptBarrelMap;
|
|
39
|
+
resourceMap?: JungleResourceMap;
|
|
38
40
|
};
|
|
39
41
|
declare type JungleInfoBase = {
|
|
40
42
|
jungles: string[];
|
|
41
43
|
manifest: string;
|
|
42
44
|
xml: ManifestXML;
|
|
43
45
|
annotations?: string[];
|
|
46
|
+
resources: JungleResourceMap;
|
|
44
47
|
};
|
|
48
|
+
export declare type JungleResourceMap = Record<string, xmlUtil.Document | Error>;
|
|
45
49
|
export declare type ResolvedJungle = JungleInfoBase & {
|
|
46
50
|
targets: Target[];
|
|
47
51
|
};
|
|
48
52
|
export declare type ResolvedBarrel = JungleInfoBase & {
|
|
49
53
|
qualifier: JungleQualifier;
|
|
50
54
|
};
|
|
51
|
-
export declare function get_jungle(jungles: string, options: BuildConfig): Promise<ResolvedJungle>;
|
|
55
|
+
export declare function get_jungle(jungles: string, options: BuildConfig, resources?: JungleResourceMap | undefined): Promise<ResolvedJungle>;
|
|
52
56
|
export {};
|
package/build/src/launch.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LineHandler } from "./util";
|
|
2
|
-
export declare function launchSimulator(): Promise<void>;
|
|
2
|
+
export declare function launchSimulator(force?: boolean): Promise<void>;
|
|
3
3
|
export declare function checkIfSimulatorRunning(): Promise<boolean>;
|
|
4
4
|
export declare function checkIfSimulatorRunningOn(port: number): Promise<boolean>;
|
|
5
|
-
export declare function simulateProgram(prg: string, device: string, test?: boolean, logger?: LineHandler | LineHandler[]): Promise<void>;
|
|
5
|
+
export declare function simulateProgram(prg: string, device: string, test?: boolean | string, logger?: LineHandler | LineHandler[]): Promise<void>;
|
package/build/src/manifest.d.ts
CHANGED
|
@@ -1,65 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
id: string;
|
|
4
|
-
entry: string;
|
|
5
|
-
launcherIcon: string;
|
|
6
|
-
minSdkVersion: string;
|
|
7
|
-
name: string;
|
|
8
|
-
type: string;
|
|
9
|
-
version: string;
|
|
10
|
-
};
|
|
11
|
-
"iq:products"?: Array<{
|
|
12
|
-
"iq:product"?: Array<{
|
|
13
|
-
$: {
|
|
14
|
-
id: string;
|
|
15
|
-
};
|
|
16
|
-
}>;
|
|
17
|
-
}>;
|
|
18
|
-
"iq:barrels"?: Array<{
|
|
19
|
-
"iq:depends"?: Array<{
|
|
20
|
-
$: {
|
|
21
|
-
name: string;
|
|
22
|
-
version: string;
|
|
23
|
-
};
|
|
24
|
-
}>;
|
|
25
|
-
}>;
|
|
26
|
-
"iq:permissions"?: Array<{
|
|
27
|
-
"iq:uses-permission"?: Array<{
|
|
28
|
-
$: {
|
|
29
|
-
id: string;
|
|
30
|
-
};
|
|
31
|
-
}>;
|
|
32
|
-
}>;
|
|
33
|
-
"iq:languages"?: Array<{
|
|
34
|
-
"iq:language"?: Array<string>;
|
|
35
|
-
}>;
|
|
36
|
-
};
|
|
37
|
-
declare type iqBarrel = {
|
|
38
|
-
$: {
|
|
39
|
-
id: string;
|
|
40
|
-
module: string;
|
|
41
|
-
version: string;
|
|
42
|
-
};
|
|
43
|
-
"iq:products"?: Array<{
|
|
44
|
-
"iq:product"?: Array<{
|
|
45
|
-
$: {
|
|
46
|
-
id: string;
|
|
47
|
-
};
|
|
48
|
-
}>;
|
|
49
|
-
}>;
|
|
50
|
-
"iq:annotations"?: Array<{
|
|
51
|
-
"iq:annotation"?: Array<string>;
|
|
52
|
-
}>;
|
|
53
|
-
};
|
|
54
|
-
export declare type ManifestXML = {
|
|
55
|
-
"iq:manifest": {
|
|
56
|
-
$: {
|
|
57
|
-
"xmlns:iq": string;
|
|
58
|
-
};
|
|
59
|
-
"iq:application"?: Array<iqApplication>;
|
|
60
|
-
"iq:barrel"?: Array<iqBarrel>;
|
|
61
|
-
};
|
|
62
|
-
};
|
|
1
|
+
import { xmlUtil } from "./sdk-util";
|
|
2
|
+
export declare type ManifestXML = xmlUtil.Document;
|
|
63
3
|
export declare function readManifest(manifest: string): Promise<ManifestXML>;
|
|
64
4
|
export declare function writeManifest(filename: string, xml: ManifestXML): Promise<void>;
|
|
65
5
|
export declare function manifestProducts(manifest: ManifestXML): string[];
|
|
@@ -68,4 +8,3 @@ export declare function manifestDropBarrels(manifest: ManifestXML): void;
|
|
|
68
8
|
export declare function manifestBarrelName(manifestName: string, manifest: ManifestXML): string;
|
|
69
9
|
export declare function manifestAnnotations(manifest: ManifestXML): string[] | undefined;
|
|
70
10
|
export declare function checkManifest(manifest: ManifestXML, products: string[]): Promise<boolean>;
|
|
71
|
-
export {};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { JungleResourceMap } from "./jungles";
|
|
2
3
|
import { BuildConfig, FilesToOptimizeMap, LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
|
|
3
4
|
export declare function getFileSources(fnMap: FilesToOptimizeMap): Promise<void>;
|
|
4
5
|
export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>;
|
|
5
|
-
export declare function analyze(fnMap: FilesToOptimizeMap,
|
|
6
|
+
export declare function analyze(fnMap: FilesToOptimizeMap, resourcesMap?: Record<string, JungleResourceMap>, config?: BuildConfig): Promise<ProgramStateAnalysis>;
|
|
7
|
+
export declare function reportMissingSymbols(state: ProgramStateAnalysis, config?: BuildConfig): void;
|
|
6
8
|
export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): mctree.Literal | mctree.AsExpression | null;
|
|
7
9
|
export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
|
|
8
|
-
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap,
|
|
10
|
+
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, resourcesMap?: Record<string, JungleResourceMap>, config?: BuildConfig): Promise<Record<string, {
|
|
9
11
|
type: import("./optimizer-types").DiagnosticType;
|
|
10
12
|
loc: {
|
|
11
13
|
start: mctree.Position;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
import { ResolvedJungle } from "./jungles";
|
|
3
2
|
export declare type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
3
|
+
export declare type LookupRules = "COMPILER1" | "COMPILER2" | "DEFAULT";
|
|
4
|
+
export declare type EnforceStatic = "YES" | "NO";
|
|
4
5
|
export declare type BuildConfig = {
|
|
5
6
|
workspace?: string;
|
|
6
7
|
jungleFiles?: string;
|
|
@@ -24,13 +25,12 @@ export declare type BuildConfig = {
|
|
|
24
25
|
returnCommand?: boolean;
|
|
25
26
|
checkBuildPragmas?: boolean;
|
|
26
27
|
checkInvalidSymbols?: DiagnosticType | "OFF";
|
|
28
|
+
checkCompilerLookupRules?: DiagnosticType | "OFF";
|
|
29
|
+
compilerLookupRules?: LookupRules;
|
|
30
|
+
enforceStatic?: EnforceStatic;
|
|
27
31
|
sizeBasedPRE?: boolean | string;
|
|
28
32
|
prettier?: Record<string, unknown>;
|
|
29
33
|
extensionVersion?: string;
|
|
30
|
-
_cache?: {
|
|
31
|
-
barrels?: Record<string, ResolvedJungle>;
|
|
32
|
-
barrelMap?: Record<string, Record<string, ResolvedJungle>>;
|
|
33
|
-
};
|
|
34
34
|
};
|
|
35
35
|
export declare type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier | mctree.EnumDeclaration;
|
|
36
36
|
export declare type StateNodeDecls = {
|
|
@@ -40,6 +40,12 @@ export declare type ImportUsing = {
|
|
|
40
40
|
node: mctree.Using | mctree.ImportModule;
|
|
41
41
|
module?: ModuleStateNode | null | undefined;
|
|
42
42
|
};
|
|
43
|
+
export declare enum StateNodeAttributes {
|
|
44
|
+
PUBLIC = 1,
|
|
45
|
+
PROTECTED = 2,
|
|
46
|
+
PRIVATE = 4,
|
|
47
|
+
STATIC = 8
|
|
48
|
+
}
|
|
43
49
|
interface BaseStateNode {
|
|
44
50
|
type: string;
|
|
45
51
|
node: mctree.Node | null | undefined;
|
|
@@ -50,6 +56,7 @@ interface BaseStateNode {
|
|
|
50
56
|
stack?: ProgramStateStack | undefined;
|
|
51
57
|
usings?: Record<string, ImportUsing>;
|
|
52
58
|
imports?: ImportUsing[];
|
|
59
|
+
attributes: StateNodeAttributes;
|
|
53
60
|
}
|
|
54
61
|
export interface ProgramStateNode extends BaseStateNode {
|
|
55
62
|
type: "Program";
|
|
@@ -87,7 +94,6 @@ export interface FunctionStateNode extends BaseStateNode {
|
|
|
87
94
|
fullName: string;
|
|
88
95
|
stack?: ProgramStateStack;
|
|
89
96
|
decls?: undefined;
|
|
90
|
-
isStatic?: boolean;
|
|
91
97
|
info?: FunctionInfo;
|
|
92
98
|
next_info?: FunctionInfo;
|
|
93
99
|
}
|
|
@@ -138,6 +144,9 @@ export declare type ProgramState = {
|
|
|
138
144
|
inType?: number;
|
|
139
145
|
inlining?: true;
|
|
140
146
|
config?: BuildConfig;
|
|
147
|
+
sdk?: string;
|
|
148
|
+
sdkVersion?: number;
|
|
149
|
+
lookupRules?: LookupRules;
|
|
141
150
|
nextExposed?: Record<string, true>;
|
|
142
151
|
exposed?: Record<string, true>;
|
|
143
152
|
usedByName?: Record<string, true>;
|
|
@@ -171,7 +180,7 @@ export declare type ProgramState = {
|
|
|
171
180
|
declare type Finalized<T, Keys extends keyof T> = T & {
|
|
172
181
|
[key in Keys]-?: NonNullable<T[key]>;
|
|
173
182
|
};
|
|
174
|
-
export declare type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed">;
|
|
183
|
+
export declare type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
|
|
175
184
|
export declare type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
|
|
176
185
|
export declare type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
|
|
177
186
|
export declare type ExcludeAnnotationsMap = {
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
|
2
2
|
import { get_jungle, ResolvedJungle, Target } from "./jungles";
|
|
3
3
|
import { launchSimulator, simulateProgram } from "./launch";
|
|
4
4
|
import { manifestProducts } from "./manifest";
|
|
5
|
-
import { copyRecursiveAsNeeded } from "./util";
|
|
6
5
|
import { BuildConfig, FilesToOptimizeMap, ProgramStateAnalysis } from "./optimizer-types";
|
|
6
|
+
import { copyRecursiveAsNeeded } from "./util";
|
|
7
7
|
export * from "./optimizer-types";
|
|
8
8
|
export { copyRecursiveAsNeeded, get_jungle, launchSimulator, manifestProducts, mctree, ResolvedJungle, simulateProgram, };
|
|
9
9
|
export declare const defaultConfig: {
|
|
@@ -18,6 +18,19 @@ declare global {
|
|
|
18
18
|
var lastModifiedSource: number;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
+
*
|
|
22
|
+
* WARNING WARNING WARNING WARNING WARNING WARNING
|
|
23
|
+
*
|
|
24
|
+
* prettier-extension-monkeyc can dynamically import this
|
|
25
|
+
* function from a local copy of @markw65/monkeyc-optimizer,
|
|
26
|
+
* rather than using the version that ships with the
|
|
27
|
+
* extension.
|
|
28
|
+
*
|
|
29
|
+
* For this to work, buildOptimizedProject's signature cannot
|
|
30
|
+
* change (or at least, can only change in a backward compatible
|
|
31
|
+
* way).
|
|
32
|
+
*
|
|
33
|
+
* DON'T CHANGE THIS FUNCTION's SIGNATURE
|
|
21
34
|
*
|
|
22
35
|
* @param {string | null} product
|
|
23
36
|
* @param {BuildConfig} options
|
|
@@ -40,13 +53,13 @@ export declare function buildOptimizedProject(product: string | null, options: B
|
|
|
40
53
|
}>;
|
|
41
54
|
export declare function generateOptimizedProject(options: BuildConfig): Promise<{
|
|
42
55
|
jungleFiles: string | undefined;
|
|
43
|
-
xml: import("./
|
|
56
|
+
xml: import("./xml-util").Document;
|
|
44
57
|
program: string;
|
|
45
58
|
hasTests: boolean;
|
|
46
59
|
diagnostics?: undefined;
|
|
47
60
|
} | {
|
|
48
61
|
jungleFiles: string;
|
|
49
|
-
xml: import("./
|
|
62
|
+
xml: import("./xml-util").Document;
|
|
50
63
|
program: string;
|
|
51
64
|
hasTests: boolean;
|
|
52
65
|
diagnostics: Record<string, {
|
package/build/src/projects.d.ts
CHANGED
|
@@ -12,10 +12,12 @@ export declare type RemoteProject = string | {
|
|
|
12
12
|
include?: string;
|
|
13
13
|
sourcePath?: string;
|
|
14
14
|
jungleContent?: string[];
|
|
15
|
+
garminOptLevel?: number;
|
|
15
16
|
};
|
|
16
17
|
export declare const githubProjects: RemoteProject[];
|
|
17
18
|
export declare function fetchGitProjects(projects: RemoteProject[]): Promise<(string | {
|
|
18
19
|
jungle: string;
|
|
19
20
|
build: boolean | null;
|
|
20
21
|
options: BuildConfig | null;
|
|
22
|
+
garminOptLevel: number | null;
|
|
21
23
|
})[]>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Program } from "@markw65/prettier-plugin-monkeyc/build/src/estree-types";
|
|
2
|
+
import { JungleResourceMap } from "./jungles";
|
|
3
|
+
import { xmlUtil } from "./sdk-util";
|
|
4
|
+
export declare function visit_resources(elements: xmlUtil.Element[], parent: string | null, visitor: (e: xmlUtil.Element, module: string | null) => void, error: (e: xmlUtil.Element, parent: string | null) => void): void;
|
|
5
|
+
export declare function add_resources_to_ast(ast: Program, resources: Record<string, JungleResourceMap>): void;
|
package/build/src/sdk-util.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { readPrg, SectionKinds } from "./readprg";
|
|
2
|
+
export * as xmlUtil from "./xml-util";
|
|
2
3
|
export declare const isWin: boolean;
|
|
3
4
|
export declare const appSupport: string;
|
|
4
5
|
export declare const connectiq: string;
|
|
@@ -15,4 +16,7 @@ export declare type DeviceInfo = {
|
|
|
15
16
|
};
|
|
16
17
|
};
|
|
17
18
|
export declare function getDeviceInfo(): Promise<DeviceInfo>;
|
|
18
|
-
export declare function getLanguages(): Promise<
|
|
19
|
+
export declare function getLanguages(): Promise<{
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
}[]>;
|
package/build/src/visitor.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
|
|
3
|
+
export declare function visitorNode(node: mctree.Node): mctree.Node;
|
|
3
4
|
export declare function visitReferences(state: ProgramStateAnalysis, ast: mctree.Program, name: string | null, defn: LookupDefinition[] | null | false, callback: (node: mctree.Node, results: LookupDefinition[], error: boolean) => undefined | false): void;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export interface Position {
|
|
2
|
+
/** >= 0 */
|
|
3
|
+
offset: number;
|
|
4
|
+
/** >= 1 */
|
|
5
|
+
line: number;
|
|
6
|
+
/** >= 0 */
|
|
7
|
+
column: number;
|
|
8
|
+
}
|
|
9
|
+
export interface SourceLocation {
|
|
10
|
+
source?: string | null | undefined;
|
|
11
|
+
start: Position;
|
|
12
|
+
end: Position;
|
|
13
|
+
}
|
|
14
|
+
interface BaseNode {
|
|
15
|
+
type: string;
|
|
16
|
+
loc?: SourceLocation | null | undefined;
|
|
17
|
+
start?: number;
|
|
18
|
+
end?: number;
|
|
19
|
+
range?: [number, number] | undefined;
|
|
20
|
+
}
|
|
21
|
+
interface CharData extends BaseNode {
|
|
22
|
+
type: "chardata";
|
|
23
|
+
value: string;
|
|
24
|
+
}
|
|
25
|
+
interface CharRef extends BaseNode {
|
|
26
|
+
type: "charref";
|
|
27
|
+
value: number;
|
|
28
|
+
base: 10 | 16;
|
|
29
|
+
}
|
|
30
|
+
interface Comment extends BaseNode {
|
|
31
|
+
type: "comment";
|
|
32
|
+
value: string;
|
|
33
|
+
}
|
|
34
|
+
interface DocTypeDecl extends BaseNode {
|
|
35
|
+
type: "doctypedecl";
|
|
36
|
+
name: string;
|
|
37
|
+
externalID?: ExternalID;
|
|
38
|
+
intSubset?: Array<MarkupDecl | PEReference>;
|
|
39
|
+
}
|
|
40
|
+
interface EntityDecl extends BaseNode {
|
|
41
|
+
type: "entitydecl";
|
|
42
|
+
name: string;
|
|
43
|
+
def: XValue;
|
|
44
|
+
kind: "&" | "%";
|
|
45
|
+
}
|
|
46
|
+
interface XValue extends BaseNode {
|
|
47
|
+
type: "entityvalue";
|
|
48
|
+
value?: Array<string | Reference | PEReference>;
|
|
49
|
+
extid?: System;
|
|
50
|
+
ndecl?: NData;
|
|
51
|
+
}
|
|
52
|
+
declare type Reference = CharRef | EntityRef;
|
|
53
|
+
declare type PEReference = PERef;
|
|
54
|
+
declare type SystemLiteral = string;
|
|
55
|
+
interface EntityRef extends BaseNode {
|
|
56
|
+
type: "entityref";
|
|
57
|
+
name: string;
|
|
58
|
+
}
|
|
59
|
+
interface PERef extends BaseNode {
|
|
60
|
+
type: "peref";
|
|
61
|
+
name: string;
|
|
62
|
+
}
|
|
63
|
+
interface NotationDecl extends BaseNode {
|
|
64
|
+
type: "notationdecl";
|
|
65
|
+
name: string;
|
|
66
|
+
id: ExternalID | PublicID;
|
|
67
|
+
}
|
|
68
|
+
interface PublicID extends BaseNode {
|
|
69
|
+
type: "publicid";
|
|
70
|
+
value: string;
|
|
71
|
+
}
|
|
72
|
+
interface NData extends BaseNode {
|
|
73
|
+
type: "ndata";
|
|
74
|
+
value: string;
|
|
75
|
+
}
|
|
76
|
+
declare type ExternalID = System | Public;
|
|
77
|
+
declare type MarkupDecl = EntityDecl | NotationDecl | PI | Comment;
|
|
78
|
+
interface System extends BaseNode {
|
|
79
|
+
type: "system";
|
|
80
|
+
value: SystemLiteral;
|
|
81
|
+
}
|
|
82
|
+
interface Public extends BaseNode {
|
|
83
|
+
type: "public";
|
|
84
|
+
value: SystemLiteral;
|
|
85
|
+
pubid: string;
|
|
86
|
+
}
|
|
87
|
+
declare type Misc = Comment | PI | CharData;
|
|
88
|
+
declare type Content = Element | Reference | CData | Misc;
|
|
89
|
+
export interface CData extends BaseNode {
|
|
90
|
+
type: "cdata";
|
|
91
|
+
value: string;
|
|
92
|
+
}
|
|
93
|
+
export interface PI extends BaseNode {
|
|
94
|
+
type: "pi";
|
|
95
|
+
name: string;
|
|
96
|
+
value: string | null;
|
|
97
|
+
}
|
|
98
|
+
export interface Element extends BaseNode {
|
|
99
|
+
type: "element";
|
|
100
|
+
name: string;
|
|
101
|
+
attr: Record<string, string>;
|
|
102
|
+
children?: Array<Content> | undefined;
|
|
103
|
+
}
|
|
104
|
+
export interface Prolog extends BaseNode {
|
|
105
|
+
type: "prolog";
|
|
106
|
+
xmldecl?: XmlDecl;
|
|
107
|
+
misc1: Misc[];
|
|
108
|
+
doctypedecl?: DocTypeDecl;
|
|
109
|
+
misc2: Misc[];
|
|
110
|
+
}
|
|
111
|
+
interface XmlDecl extends BaseNode {
|
|
112
|
+
type: "xmldecl";
|
|
113
|
+
version: "1.0";
|
|
114
|
+
encoding?: string[];
|
|
115
|
+
standalone?: string[];
|
|
116
|
+
}
|
|
117
|
+
export declare class Document {
|
|
118
|
+
prolog: Prolog;
|
|
119
|
+
body: Nodes;
|
|
120
|
+
misc: Array<Misc>;
|
|
121
|
+
source?: string | undefined;
|
|
122
|
+
constructor(prolog: Prolog, body: Nodes, misc: Array<Misc>, source?: string | undefined);
|
|
123
|
+
}
|
|
124
|
+
export declare function elementKids(e: Element): Element[];
|
|
125
|
+
declare type ElementMatcher = string | ((c: Element) => boolean);
|
|
126
|
+
export declare class Nodes {
|
|
127
|
+
elements: Array<Element>;
|
|
128
|
+
constructor(elements: Element | Element[]);
|
|
129
|
+
length(): number;
|
|
130
|
+
deleteChildren(arg: ElementMatcher): void;
|
|
131
|
+
addChildren(elements: Element[]): void;
|
|
132
|
+
filter(arg: ElementMatcher): Nodes;
|
|
133
|
+
skip(name: string): Nodes;
|
|
134
|
+
children(name?: string): Nodes;
|
|
135
|
+
text(): string[];
|
|
136
|
+
attrs(): Record<string, string>[];
|
|
137
|
+
}
|
|
138
|
+
export declare function parseXml(content: string, fileName?: string | null): Document;
|
|
139
|
+
export declare function writeXml(doc: Document): string;
|
|
140
|
+
export {};
|