@idlizer/core 2.1.9-arktscgen-6 → 2.1.9-arktscgen-9
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/build/lib/src/IndentedPrinter.d.ts +2 -1
- package/build/lib/src/IndentedPrinter.js +9 -2
- package/build/lib/src/Language.d.ts +0 -1
- package/build/lib/src/Language.js +7 -8
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +27 -40
- package/build/lib/src/LanguageWriters/ArgConvertors.js +167 -206
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +13 -34
- package/build/lib/src/LanguageWriters/LanguageWriter.js +31 -82
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +2 -2
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.d.ts +17 -1
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +121 -6
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +6 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +2 -3
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +9 -25
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +0 -5
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +0 -9
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +4 -6
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +15 -28
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +14 -10
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +51 -74
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +2 -8
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +11 -21
- package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +12 -9
- package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +121 -32
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +5 -6
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +17 -33
- package/build/lib/src/config.d.ts +402 -133
- package/build/lib/src/config.js +13 -7
- package/build/lib/src/diagnosticmessages.d.ts +45 -0
- package/build/lib/src/diagnosticmessages.js +66 -0
- package/build/lib/src/diagnostictypes.d.ts +140 -0
- package/build/lib/src/diagnostictypes.js +72 -0
- package/build/lib/src/formatter.d.ts +3 -0
- package/build/lib/src/formatter.js +98 -0
- package/build/lib/src/from-idl/deserialize.d.ts +1 -0
- package/build/lib/src/from-idl/deserialize.js +107 -5
- package/build/lib/src/idl.d.ts +8 -0
- package/build/lib/src/idl.js +16 -3
- package/build/lib/src/index.d.ts +7 -1
- package/build/lib/src/index.js +7 -1
- package/build/lib/src/peer-generation/Materialized.d.ts +2 -2
- package/build/lib/src/peer-generation/Materialized.js +4 -9
- package/build/lib/src/peer-generation/PeerLibrary.js +1 -5
- package/build/lib/src/peer-generation/PeerMethod.d.ts +0 -4
- package/build/lib/src/peer-generation/PeerMethod.js +18 -36
- package/build/lib/src/peer-generation/idl/common.js +1 -1
- package/build/lib/src/peer-generation/isMaterialized.js +0 -4
- package/build/lib/src/peer-generation/modules.d.ts +1 -0
- package/build/lib/src/peer-generation/modules.js +25 -6
- package/build/lib/src/peer-generation/unions.d.ts +0 -2
- package/build/lib/src/peer-generation/unions.js +3 -23
- package/build/lib/src/transformers/FqnTransformer.d.ts +4 -0
- package/build/lib/src/transformers/FqnTransformer.js +17 -0
- package/build/lib/src/transformers/GenericTransformer.d.ts +8 -0
- package/build/lib/src/transformers/GenericTransformer.js +141 -0
- package/build/lib/src/util.d.ts +5 -2
- package/build/lib/src/util.js +26 -12
- package/package.json +2 -2
- package/build/lib/src/peer-generation/isExternalType.d.ts +0 -4
- package/build/lib/src/peer-generation/isExternalType.js +0 -15
package/build/lib/src/config.js
CHANGED
|
@@ -19,11 +19,13 @@ const T = {
|
|
|
19
19
|
};
|
|
20
20
|
export const ModuleConfigurationSchema = D.object({
|
|
21
21
|
name: D.string(),
|
|
22
|
+
external: D.maybe(D.boolean()),
|
|
22
23
|
packages: T.stringArray(),
|
|
23
24
|
useFoldersLayout: D.maybe(D.boolean()),
|
|
24
25
|
});
|
|
25
26
|
export const HookMethodSchema = D.object({
|
|
26
27
|
hookName: D.string(),
|
|
28
|
+
replaceImplementation: D.boolean()
|
|
27
29
|
});
|
|
28
30
|
export const CoreConfigurationSchema = D.object({
|
|
29
31
|
TypePrefix: D.string(),
|
|
@@ -33,16 +35,16 @@ export const CoreConfigurationSchema = D.object({
|
|
|
33
35
|
standaloneComponents: T.stringArray(),
|
|
34
36
|
parameterized: T.stringArray(),
|
|
35
37
|
ignoreMaterialized: T.stringArray(),
|
|
38
|
+
ignoreGenerics: T.stringArray(),
|
|
36
39
|
builderClasses: T.stringArray(),
|
|
37
40
|
forceMaterialized: T.stringArray(),
|
|
38
41
|
forceCallback: D.map(D.string(), T.stringArray()).onMerge('replace'),
|
|
39
42
|
forceResource: T.stringArray(),
|
|
40
43
|
forceContext: T.stringArray(),
|
|
41
44
|
hooks: D.map(D.string(), D.map(D.string(), HookMethodSchema)).onMerge('replace'),
|
|
42
|
-
externalTypes: D.map(D.string(), D.string()).onMerge('replace'),
|
|
43
|
-
externalPackages: T.stringArray(),
|
|
44
45
|
moduleName: D.string(),
|
|
45
46
|
modules: D.map(D.string(), ModuleConfigurationSchema).onMerge('replace'),
|
|
47
|
+
libraryNameMapping: D.maybe(D.map(D.string(), D.map(D.string(), D.string())).onMerge('replace')),
|
|
46
48
|
globalPackages: T.stringArray()
|
|
47
49
|
});
|
|
48
50
|
export const defaultCoreConfiguration = {
|
|
@@ -53,16 +55,16 @@ export const defaultCoreConfiguration = {
|
|
|
53
55
|
standaloneComponents: [],
|
|
54
56
|
parameterized: [],
|
|
55
57
|
ignoreMaterialized: [],
|
|
58
|
+
ignoreGenerics: [],
|
|
56
59
|
builderClasses: [],
|
|
57
60
|
forceMaterialized: [],
|
|
58
61
|
forceCallback: new Map(),
|
|
59
62
|
forceResource: [],
|
|
60
63
|
forceContext: [],
|
|
61
64
|
hooks: new Map(),
|
|
62
|
-
externalTypes: new Map(),
|
|
63
|
-
externalPackages: [],
|
|
64
65
|
moduleName: "",
|
|
65
66
|
modules: new Map(),
|
|
67
|
+
libraryNameMapping: new Map(),
|
|
66
68
|
globalPackages: []
|
|
67
69
|
};
|
|
68
70
|
let currentConfig = defaultCoreConfiguration;
|
|
@@ -79,14 +81,18 @@ export function generatorTypePrefix() {
|
|
|
79
81
|
const conf = generatorConfiguration();
|
|
80
82
|
return `${conf.TypePrefix}${conf.LibraryPrefix}`;
|
|
81
83
|
}
|
|
82
|
-
export function
|
|
83
|
-
var _a;
|
|
84
|
+
export function getHookMethod(className, methodName) {
|
|
85
|
+
var _a, _b;
|
|
84
86
|
const hookMethods = generatorConfiguration().hooks.get(className);
|
|
85
87
|
if (!hookMethods)
|
|
86
88
|
return undefined;
|
|
87
89
|
const hook = hookMethods.get(methodName);
|
|
88
90
|
if (!hook)
|
|
89
91
|
return undefined;
|
|
90
|
-
|
|
92
|
+
const method = {
|
|
93
|
+
hookName: (_a = hook.hookName) !== null && _a !== void 0 ? _a : `hook${className}${capitalize(methodName)}`,
|
|
94
|
+
replaceImplementation: (_b = hook.replaceImplementation) !== null && _b !== void 0 ? _b : true
|
|
95
|
+
};
|
|
96
|
+
return method;
|
|
91
97
|
}
|
|
92
98
|
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { MessageSeverity, DiagnosticMessage, Location, DiagnosticResults } from "./diagnostictypes";
|
|
2
|
+
/**
|
|
3
|
+
* Template for registering different kinds of messages
|
|
4
|
+
*/
|
|
5
|
+
export declare class DiagnosticMessageEntry {
|
|
6
|
+
/**
|
|
7
|
+
* Index for DiagnosticMessageEntry by code
|
|
8
|
+
*/
|
|
9
|
+
static diagnosticMessageByCode: Map<number, DiagnosticMessageEntry>;
|
|
10
|
+
static collectedResults: DiagnosticResults;
|
|
11
|
+
/**
|
|
12
|
+
* Severity of the diagnostic.
|
|
13
|
+
*/
|
|
14
|
+
severity: MessageSeverity;
|
|
15
|
+
/**
|
|
16
|
+
* Unsigned integer code of the diagnostic.
|
|
17
|
+
*/
|
|
18
|
+
code: number;
|
|
19
|
+
/**
|
|
20
|
+
* Description of the diagnostic.
|
|
21
|
+
*/
|
|
22
|
+
codeDescription: string;
|
|
23
|
+
/**
|
|
24
|
+
* An URI to open with more information about the diagnostic.
|
|
25
|
+
*/
|
|
26
|
+
codeURI?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Template for main part
|
|
29
|
+
*/
|
|
30
|
+
mainMessageTemplate: string;
|
|
31
|
+
/**
|
|
32
|
+
* Template for additional parts
|
|
33
|
+
*/
|
|
34
|
+
additionalMessageTemplate: string;
|
|
35
|
+
constructor(severity: MessageSeverity, code: number, codeDescription: string, mainMessageTemplate?: string, additionalMessageTemplate?: string);
|
|
36
|
+
generateDiagnosticMessage(locations: Location[], mainMessage?: string, additionalMessage?: string): DiagnosticMessage;
|
|
37
|
+
reportDiagnosticMessage(locations: Location[], mainMessage?: string, additionalMessage?: string): void;
|
|
38
|
+
throwDiagnosticMessage(locations: Location[], mainMessage?: string, additionalMessage?: string): void;
|
|
39
|
+
static reportCatched(diagnosticMessage: DiagnosticMessage): void;
|
|
40
|
+
}
|
|
41
|
+
export declare const UnknownErrorMessage: DiagnosticMessageEntry;
|
|
42
|
+
export declare const LoadingErrorMessage: DiagnosticMessageEntry;
|
|
43
|
+
export declare const ParsingErrorMessage: DiagnosticMessageEntry;
|
|
44
|
+
export declare const ProcessingErrorMessage: DiagnosticMessageEntry;
|
|
45
|
+
//# sourceMappingURL=diagnosticmessages.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import { DiagnosticException, DiagnosticResults } from "./diagnostictypes";
|
|
16
|
+
/**
|
|
17
|
+
* Template for registering different kinds of messages
|
|
18
|
+
*/
|
|
19
|
+
export class DiagnosticMessageEntry {
|
|
20
|
+
constructor(severity, code, codeDescription, mainMessageTemplate, additionalMessageTemplate) {
|
|
21
|
+
this.severity = severity;
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.codeDescription = codeDescription;
|
|
24
|
+
// No cases of codeUri for now, can be embedded into codeDescription later if needed
|
|
25
|
+
this.mainMessageTemplate = mainMessageTemplate !== null && mainMessageTemplate !== void 0 ? mainMessageTemplate : codeDescription;
|
|
26
|
+
this.additionalMessageTemplate = additionalMessageTemplate !== null && additionalMessageTemplate !== void 0 ? additionalMessageTemplate : "See";
|
|
27
|
+
if (DiagnosticMessageEntry.diagnosticMessageByCode.has(code)) {
|
|
28
|
+
throw new Error(`Duplicate message code ${code}`);
|
|
29
|
+
}
|
|
30
|
+
DiagnosticMessageEntry.diagnosticMessageByCode.set(code, this);
|
|
31
|
+
}
|
|
32
|
+
generateDiagnosticMessage(locations, mainMessage, additionalMessage) {
|
|
33
|
+
let msg = {
|
|
34
|
+
severity: this.severity,
|
|
35
|
+
code: this.code,
|
|
36
|
+
codeDescription: this.codeDescription,
|
|
37
|
+
codeURI: this.codeURI,
|
|
38
|
+
parts: []
|
|
39
|
+
};
|
|
40
|
+
let first = true;
|
|
41
|
+
for (const l of locations) {
|
|
42
|
+
msg.parts.push({ location: l, message: first ? (mainMessage !== null && mainMessage !== void 0 ? mainMessage : this.mainMessageTemplate) : (additionalMessage !== null && additionalMessage !== void 0 ? additionalMessage : this.additionalMessageTemplate) });
|
|
43
|
+
first = false;
|
|
44
|
+
}
|
|
45
|
+
return msg;
|
|
46
|
+
}
|
|
47
|
+
reportDiagnosticMessage(locations, mainMessage, additionalMessage) {
|
|
48
|
+
DiagnosticMessageEntry.collectedResults.push(this.generateDiagnosticMessage(locations, mainMessage, additionalMessage));
|
|
49
|
+
}
|
|
50
|
+
throwDiagnosticMessage(locations, mainMessage, additionalMessage) {
|
|
51
|
+
throw new DiagnosticException(this.generateDiagnosticMessage(locations, mainMessage, additionalMessage));
|
|
52
|
+
}
|
|
53
|
+
static reportCatched(diagnosticMessage) {
|
|
54
|
+
this.collectedResults.push(diagnosticMessage);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Index for DiagnosticMessageEntry by code
|
|
59
|
+
*/
|
|
60
|
+
DiagnosticMessageEntry.diagnosticMessageByCode = new Map();
|
|
61
|
+
DiagnosticMessageEntry.collectedResults = new DiagnosticResults();
|
|
62
|
+
export const UnknownErrorMessage = new DiagnosticMessageEntry("fatal", 0, "Unknown error");
|
|
63
|
+
export const LoadingErrorMessage = new DiagnosticMessageEntry("fatal", 100, "Loading error");
|
|
64
|
+
export const ParsingErrorMessage = new DiagnosticMessageEntry("fatal", 101, "Parsing error");
|
|
65
|
+
export const ProcessingErrorMessage = new DiagnosticMessageEntry("fatal", 102, "Processing error");
|
|
66
|
+
//# sourceMappingURL=diagnosticmessages.js.map
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic message severity.
|
|
3
|
+
* LSP note: Corresponds directly.
|
|
4
|
+
*/
|
|
5
|
+
export type MessageSeverity = "fatal" | "error" | "warning" | "information" | "hint";
|
|
6
|
+
/**
|
|
7
|
+
* Diagnostic message severity values.
|
|
8
|
+
*/
|
|
9
|
+
export declare let MessageSeverityList: MessageSeverity[];
|
|
10
|
+
/**
|
|
11
|
+
* Message that reports specific error/warning, contains multiple parts and fixes.
|
|
12
|
+
* LSP note:
|
|
13
|
+
* DiagnosticMessage is designed to be easily convertible to LSP data structures.
|
|
14
|
+
* The main fields and first DiagnosticComponent can be mapped to LSP Diagnostic.
|
|
15
|
+
* Rest of `parts` - to `relatedInformation` in it.
|
|
16
|
+
* Fields like `fixes` - to other LSP API.
|
|
17
|
+
*/
|
|
18
|
+
export interface DiagnosticMessage {
|
|
19
|
+
/**
|
|
20
|
+
* Severity of the diagnostic.
|
|
21
|
+
*/
|
|
22
|
+
severity: MessageSeverity;
|
|
23
|
+
/**
|
|
24
|
+
* Unsigned integer code of the diagnostic.
|
|
25
|
+
*/
|
|
26
|
+
code: number;
|
|
27
|
+
/**
|
|
28
|
+
* Description of the diagnostic.
|
|
29
|
+
*/
|
|
30
|
+
codeDescription: string;
|
|
31
|
+
/**
|
|
32
|
+
* An URI to open with more information about the diagnostic.
|
|
33
|
+
*/
|
|
34
|
+
codeURI?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Main and clarifying components of the diagnostic with locations.
|
|
37
|
+
*/
|
|
38
|
+
parts: DiagnosticComponent[];
|
|
39
|
+
/**
|
|
40
|
+
* List of diffs that can be applied to source files to fix the problem reported in diagnostic. Optional.
|
|
41
|
+
*/
|
|
42
|
+
fixes?: DiagnosticDiffComponent[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Component of diagnostic message related to specific file/location.
|
|
46
|
+
*/
|
|
47
|
+
export interface DiagnosticComponent {
|
|
48
|
+
/**
|
|
49
|
+
* Location (document path and optional range)
|
|
50
|
+
*/
|
|
51
|
+
location: Location;
|
|
52
|
+
/**
|
|
53
|
+
* Message related to specific character range or the document as a whole.
|
|
54
|
+
*/
|
|
55
|
+
message: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Location, consisting of document path and optional range
|
|
59
|
+
*/
|
|
60
|
+
export interface Location {
|
|
61
|
+
/**
|
|
62
|
+
* Path to correspondent document.
|
|
63
|
+
*/
|
|
64
|
+
documentPath: string;
|
|
65
|
+
/**
|
|
66
|
+
* Character range in that document, optional.
|
|
67
|
+
*/
|
|
68
|
+
range?: Range;
|
|
69
|
+
/**
|
|
70
|
+
* Document content for pretty formatted output, optional.
|
|
71
|
+
*/
|
|
72
|
+
lines?: string[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Location, consisting two inclusive in-document positions.
|
|
76
|
+
*/
|
|
77
|
+
export interface Range {
|
|
78
|
+
/**
|
|
79
|
+
* Start position (inclusive).
|
|
80
|
+
*/
|
|
81
|
+
start: Position;
|
|
82
|
+
/**
|
|
83
|
+
* End position (exclusive).
|
|
84
|
+
*/
|
|
85
|
+
end: Position;
|
|
86
|
+
}
|
|
87
|
+
export declare function commonRange(range1: Range, range2: Range): Range;
|
|
88
|
+
/**
|
|
89
|
+
* Position in a document.
|
|
90
|
+
* LSP note: In LSP positions are zero-based (that needs conversion) and UTF-16 by default.
|
|
91
|
+
*/
|
|
92
|
+
export interface Position {
|
|
93
|
+
/**
|
|
94
|
+
* Line position in a document (one-based).
|
|
95
|
+
*/
|
|
96
|
+
line: number;
|
|
97
|
+
/**
|
|
98
|
+
* Character offset on a line in a document (one-based) in UTF-16 code points.
|
|
99
|
+
*/
|
|
100
|
+
character: number;
|
|
101
|
+
}
|
|
102
|
+
export declare function comparePositions(a: Position, b: Position): number;
|
|
103
|
+
export declare function minPosition(a: Position, b: Position): Position;
|
|
104
|
+
export declare function maxPosition(a: Position, b: Position): Position;
|
|
105
|
+
/**
|
|
106
|
+
* Diff component of diagnostic message related to specific file/location.
|
|
107
|
+
*/
|
|
108
|
+
export interface DiagnosticDiffComponent {
|
|
109
|
+
/**
|
|
110
|
+
* Location (document path and optional range)
|
|
111
|
+
*/
|
|
112
|
+
location: Location;
|
|
113
|
+
/**
|
|
114
|
+
* Replacement content. Can be omitted for the "whole document" case, meaning that document needs to be deleted.
|
|
115
|
+
*/
|
|
116
|
+
replacement?: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Receiver of diagnostic messages.
|
|
120
|
+
*/
|
|
121
|
+
export interface DiagnosticReceiver {
|
|
122
|
+
push(message: DiagnosticMessage): void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Collection of diagnostic messages with calculated statistics.
|
|
126
|
+
*/
|
|
127
|
+
export declare class DiagnosticResults implements DiagnosticReceiver {
|
|
128
|
+
entries: DiagnosticMessage[];
|
|
129
|
+
totals: Record<MessageSeverity, number>;
|
|
130
|
+
push(message: DiagnosticMessage): void;
|
|
131
|
+
get hasErrors(): boolean;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Exception for delivering prepared DiagnosticMessage through processing
|
|
135
|
+
*/
|
|
136
|
+
export declare class DiagnosticException extends Error {
|
|
137
|
+
diagnosticMessage: DiagnosticMessage;
|
|
138
|
+
constructor(diagnosticMessage: DiagnosticMessage, cause?: any);
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=diagnostictypes.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Diagnostic message severity values.
|
|
17
|
+
*/
|
|
18
|
+
export let MessageSeverityList = ["fatal", "error", "warning", "information", "hint"];
|
|
19
|
+
export function commonRange(range1, range2) {
|
|
20
|
+
let start = minPosition(range1.start, range2.start);
|
|
21
|
+
let end = maxPosition(range1.end, range2.end);
|
|
22
|
+
return { start, end };
|
|
23
|
+
}
|
|
24
|
+
export function comparePositions(a, b) {
|
|
25
|
+
if (a.line < b.line) {
|
|
26
|
+
return -1;
|
|
27
|
+
}
|
|
28
|
+
if (a.line > b.line) {
|
|
29
|
+
return 1;
|
|
30
|
+
}
|
|
31
|
+
if (a.character < b.character) {
|
|
32
|
+
return -1;
|
|
33
|
+
}
|
|
34
|
+
if (a.character > b.character) {
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
export function minPosition(a, b) {
|
|
40
|
+
return comparePositions(a, b) == -1 ? a : b;
|
|
41
|
+
}
|
|
42
|
+
export function maxPosition(a, b) {
|
|
43
|
+
return comparePositions(a, b) == 1 ? a : b;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Collection of diagnostic messages with calculated statistics.
|
|
47
|
+
*/
|
|
48
|
+
export class DiagnosticResults {
|
|
49
|
+
constructor() {
|
|
50
|
+
this.entries = [];
|
|
51
|
+
this.totals = { "fatal": 0, "error": 0, "warning": 0, "information": 0, "hint": 0 };
|
|
52
|
+
}
|
|
53
|
+
push(message) {
|
|
54
|
+
this.entries.push(message);
|
|
55
|
+
this.totals[message.severity] += 1;
|
|
56
|
+
}
|
|
57
|
+
get hasErrors() {
|
|
58
|
+
return this.totals.fatal != 0 || this.totals.error != 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Exception for delivering prepared DiagnosticMessage through processing
|
|
63
|
+
*/
|
|
64
|
+
export class DiagnosticException extends Error {
|
|
65
|
+
constructor(diagnosticMessage, cause) {
|
|
66
|
+
super();
|
|
67
|
+
this.message = diagnosticMessage.parts[0].message;
|
|
68
|
+
this.diagnosticMessage = diagnosticMessage;
|
|
69
|
+
this.cause = cause;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=diagnostictypes.js.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import { MessageSeverityList } from "./diagnostictypes";
|
|
16
|
+
export function outputDiagnosticResultsFormatted(result) {
|
|
17
|
+
for (let message of result.entries) {
|
|
18
|
+
outputReadableMessage(message);
|
|
19
|
+
}
|
|
20
|
+
outputReadableTotals(result);
|
|
21
|
+
}
|
|
22
|
+
function outputReadableTotals(result) {
|
|
23
|
+
let totals = [];
|
|
24
|
+
for (let k of MessageSeverityList) {
|
|
25
|
+
totals.push(`${k}: ${result.totals[k]}`);
|
|
26
|
+
}
|
|
27
|
+
console.log(totals.join(", "));
|
|
28
|
+
}
|
|
29
|
+
function lineDigitCount(message) {
|
|
30
|
+
let count = 0;
|
|
31
|
+
for (let part of message.parts) {
|
|
32
|
+
let range = part.location.range;
|
|
33
|
+
if (range == null) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
count = Math.max(count, range.start.line.toString().length, range.end.line.toString().length);
|
|
37
|
+
}
|
|
38
|
+
return count;
|
|
39
|
+
}
|
|
40
|
+
function paddedLineNo(digits, line) {
|
|
41
|
+
let s = line.toString();
|
|
42
|
+
if (s.length < digits) {
|
|
43
|
+
return " ".repeat(digits - s.length) + s;
|
|
44
|
+
}
|
|
45
|
+
return s;
|
|
46
|
+
}
|
|
47
|
+
function formatLine(digits, lines, lineNo) {
|
|
48
|
+
return `${paddedLineNo(digits, lineNo)} | ${lines[lineNo - 1]}`;
|
|
49
|
+
}
|
|
50
|
+
function formatUnderline(indent, lines, lineNo, range, edgeChar, midChar, message) {
|
|
51
|
+
if (lineNo == range.start.line && lineNo == range.end.line) {
|
|
52
|
+
let len = range.end.character - range.start.character + 1;
|
|
53
|
+
return `${indent} | ${" ".repeat(range.start.character - 1)}${edgeChar}${len > 2 ? midChar.repeat(len - 2) : ""}${len > 1 ? edgeChar : ""} ${message}`;
|
|
54
|
+
}
|
|
55
|
+
if (lineNo == range.start.line) {
|
|
56
|
+
let len = lines[lineNo - 1].length - range.start.character;
|
|
57
|
+
return `${indent} | ${" ".repeat(range.start.character - 1)}${edgeChar}${len > 1 ? midChar.repeat(len - 1) : ""}`;
|
|
58
|
+
}
|
|
59
|
+
if (lineNo == range.end.line) {
|
|
60
|
+
let len = range.end.character;
|
|
61
|
+
return `${indent} | ${len > 1 ? midChar.repeat(len - 1) : ""}${edgeChar} ${message}`;
|
|
62
|
+
}
|
|
63
|
+
return `${indent} | ${midChar.repeat(lines[lineNo - 1].length)}`;
|
|
64
|
+
}
|
|
65
|
+
function outputReadableMessage(message) {
|
|
66
|
+
if (message.parts.length == 0) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
console.log(`${message.severity}[E${message.code}]: ${message.codeDescription}`);
|
|
70
|
+
let digits = lineDigitCount(message);
|
|
71
|
+
let indent = " ".repeat(digits);
|
|
72
|
+
let first = true;
|
|
73
|
+
let lastPath = "";
|
|
74
|
+
for (let part of message.parts) {
|
|
75
|
+
const location = part.location;
|
|
76
|
+
if (location.range != null && location.lines != null) {
|
|
77
|
+
let range = location.range;
|
|
78
|
+
let lines = location.lines;
|
|
79
|
+
console.log(`${indent}${lastPath != part.location.documentPath ? "-->" : ":::"} ${part.location.documentPath}:${range.start.line}:${range.start.character}`);
|
|
80
|
+
console.log(`${indent} |`);
|
|
81
|
+
for (let i = range.start.line; i <= range.end.line; ++i) {
|
|
82
|
+
console.log(formatLine(digits, lines, i));
|
|
83
|
+
console.log(formatUnderline(indent, lines, i, range, "^", first ? "-" : "~", part.message));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
console.log(`${indent}--> ${part.location.documentPath}`);
|
|
88
|
+
if (message.parts.length > 1) {
|
|
89
|
+
console.log(`${indent} # ${part.message}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
first = false;
|
|
93
|
+
lastPath = part.location.documentPath;
|
|
94
|
+
}
|
|
95
|
+
console.log(`${indent} = ${message.parts[0].message}`);
|
|
96
|
+
console.log();
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -9,6 +9,7 @@ interface ToIDLFileProps {
|
|
|
9
9
|
inheritanceMode?: IDLInheritanceMode;
|
|
10
10
|
content?: string;
|
|
11
11
|
}
|
|
12
|
+
export declare function toIdlType(fileName: string, content: string): idl.IDLType;
|
|
12
13
|
export declare function toIDLFile(fileName: string, { content, inheritanceMode }?: ToIDLFileProps): [idl.IDLFile, IDLTokenInfoMap];
|
|
13
14
|
export {};
|
|
14
15
|
//# sourceMappingURL=deserialize.d.ts.map
|
|
@@ -19,6 +19,8 @@ import { toString } from "./toString";
|
|
|
19
19
|
import * as idl from "../idl";
|
|
20
20
|
import { isDefined, warn } from "../util";
|
|
21
21
|
import { collapseTypes, generateSyntheticUnionName } from "../peer-generation/idl/common";
|
|
22
|
+
import { commonRange } from "../diagnostictypes";
|
|
23
|
+
import { LoadingErrorMessage, ParsingErrorMessage, UnknownErrorMessage } from "../diagnosticmessages";
|
|
22
24
|
function getTokens(node) {
|
|
23
25
|
return node.tokens;
|
|
24
26
|
}
|
|
@@ -512,13 +514,42 @@ class IDLDeserializer {
|
|
|
512
514
|
return attr ? this.toExtendedAttributeValue(attr) : undefined;
|
|
513
515
|
}
|
|
514
516
|
}
|
|
517
|
+
export function toIdlType(fileName, content) {
|
|
518
|
+
const lexicalInfo = new Map();
|
|
519
|
+
const deserializer = new IDLDeserializer(lexicalInfo, 'multiple');
|
|
520
|
+
return deserializer.toIDLType(fileName, webidl2.parseType(content, fileName));
|
|
521
|
+
}
|
|
515
522
|
export function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
|
|
523
|
+
var _a, _b, _c;
|
|
516
524
|
const lexicalInfo = new Map();
|
|
517
525
|
const deserializer = new IDLDeserializer(lexicalInfo, inheritanceMode);
|
|
518
|
-
if (undefined === content)
|
|
519
|
-
|
|
526
|
+
if (undefined === content) {
|
|
527
|
+
try {
|
|
528
|
+
content = fs.readFileSync(fileName).toString();
|
|
529
|
+
}
|
|
530
|
+
catch (e) {
|
|
531
|
+
content = "";
|
|
532
|
+
LoadingErrorMessage.throwDiagnosticMessage([{ documentPath: fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "");
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
let lines = (_b = content.match(/[^\r\n]*(\n|\r\n)?/g)) !== null && _b !== void 0 ? _b : [];
|
|
536
|
+
const offsets = prepareOffsets(lines);
|
|
537
|
+
lines = lines.map((s) => s.replace(/(\n|\r\n)$/, ""));
|
|
538
|
+
const parsed = { fileName, lines, offsets, lexicalInfo };
|
|
520
539
|
let packageClause = [];
|
|
521
|
-
|
|
540
|
+
let rawParsingResults;
|
|
541
|
+
try {
|
|
542
|
+
rawParsingResults = webidl2.parse(content);
|
|
543
|
+
}
|
|
544
|
+
catch (e) {
|
|
545
|
+
if (e.name == "WebIDLParseError") {
|
|
546
|
+
let tokens = e.tokens;
|
|
547
|
+
let range = tokens.length > 0 ? rangeForToken(offsets, tokens[0]) : undefined;
|
|
548
|
+
ParsingErrorMessage.throwDiagnosticMessage([{ documentPath: fileName, range, lines }], e.bareMessage);
|
|
549
|
+
}
|
|
550
|
+
UnknownErrorMessage.throwDiagnosticMessage([{ documentPath: fileName }], (_c = e.message) !== null && _c !== void 0 ? _c : "");
|
|
551
|
+
}
|
|
552
|
+
const entries = rawParsingResults
|
|
522
553
|
.filter(it => {
|
|
523
554
|
if (!it.type)
|
|
524
555
|
return false;
|
|
@@ -530,8 +561,79 @@ export function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } =
|
|
|
530
561
|
return true;
|
|
531
562
|
})
|
|
532
563
|
.map(it => deserializer.toIDLNode(fileName, it));
|
|
533
|
-
|
|
564
|
+
let file = idl.createFile(entries, fileName, packageClause);
|
|
534
565
|
file.text = content;
|
|
535
|
-
|
|
566
|
+
file = idl.linkParentBack(file);
|
|
567
|
+
idl.forEachChild(file, (node) => {
|
|
568
|
+
node.nodeLocation = locationForNode(parsed, node);
|
|
569
|
+
const nameLocation = locationForNode(parsed, node, "name");
|
|
570
|
+
if (nameLocation.range) {
|
|
571
|
+
node.nameLocation = nameLocation;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
return [file, lexicalInfo];
|
|
575
|
+
}
|
|
576
|
+
function prepareOffsets(lines) {
|
|
577
|
+
let offsets = [];
|
|
578
|
+
let offset = 0;
|
|
579
|
+
for (let line of lines) {
|
|
580
|
+
let plus = line.length;
|
|
581
|
+
offsets.push(offset);
|
|
582
|
+
offset += plus;
|
|
583
|
+
}
|
|
584
|
+
return offsets;
|
|
585
|
+
}
|
|
586
|
+
function locationForNode(parsed, node, component) {
|
|
587
|
+
if (node.kind == idl.IDLKind.File) {
|
|
588
|
+
return { documentPath: parsed.fileName, lines: parsed.lines };
|
|
589
|
+
}
|
|
590
|
+
return { documentPath: parsed.fileName, range: rangeForNode(parsed, node, component), lines: parsed.lines };
|
|
591
|
+
}
|
|
592
|
+
function rangeForNode(parsed, node, component) {
|
|
593
|
+
var _a;
|
|
594
|
+
let info = parsed.lexicalInfo.get(node);
|
|
595
|
+
if (info == null) {
|
|
596
|
+
// Proper solution will require fixes with inheritance tokens in Idlize/core and custom webidl2.js
|
|
597
|
+
// So now we are extracting from what we have
|
|
598
|
+
if (node.parent) {
|
|
599
|
+
return (_a = rangeForNode(parsed, node.parent, "inheritance")) !== null && _a !== void 0 ? _a : rangeForNode(parsed, node.parent);
|
|
600
|
+
}
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
let range;
|
|
604
|
+
for (let k of Object.keys(info)) {
|
|
605
|
+
if (component && k != component) {
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
608
|
+
let named = info[k];
|
|
609
|
+
if (named == null) {
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (named.value == null) {
|
|
613
|
+
if (k == "inheritance" && Array.isArray(named)) {
|
|
614
|
+
for (let inh of named) {
|
|
615
|
+
if (inh.inheritance == null) {
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
let newRange = rangeForToken(parsed.offsets, inh.inheritance);
|
|
619
|
+
range = range ? commonRange(range, newRange) : newRange;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
let newRange = rangeForToken(parsed.offsets, named);
|
|
625
|
+
range = range ? commonRange(range, newRange) : newRange;
|
|
626
|
+
}
|
|
627
|
+
return range;
|
|
628
|
+
}
|
|
629
|
+
function rangeForToken(offsets, token) {
|
|
630
|
+
let dif = token.value.length - 1;
|
|
631
|
+
if (dif < 0) {
|
|
632
|
+
dif = 0;
|
|
633
|
+
}
|
|
634
|
+
let endline = token.line + (token.value.match(/\n/g) || []).length;
|
|
635
|
+
let character = token.position - offsets[token.line - 1] + 1;
|
|
636
|
+
let endcharacter = token.position + dif - offsets[endline - 1] + 1;
|
|
637
|
+
return { start: { line: token.line, character: character }, end: { line: endline, character: endcharacter } };
|
|
536
638
|
}
|
|
537
639
|
//# sourceMappingURL=deserialize.js.map
|
package/build/lib/src/idl.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { stringOrNone } from "./util";
|
|
2
|
+
import { Location } from "./diagnostictypes";
|
|
2
3
|
export declare enum IDLKind {
|
|
3
4
|
Interface = "Interface",
|
|
4
5
|
Import = "Import",
|
|
@@ -45,6 +46,7 @@ export declare enum IDLExtendedAttributes {
|
|
|
45
46
|
DtsTag = "DtsTag",
|
|
46
47
|
Entity = "Entity",
|
|
47
48
|
Extends = "Extends",
|
|
49
|
+
ExtensionMethod = "ExtensionMethod",
|
|
48
50
|
Import = "Import",
|
|
49
51
|
DefaultExport = "DefaultExport",
|
|
50
52
|
IndexSignature = "IndexSignature",
|
|
@@ -52,6 +54,7 @@ export declare enum IDLExtendedAttributes {
|
|
|
52
54
|
NativeModule = "NativeModule",
|
|
53
55
|
Optional = "Optional",
|
|
54
56
|
OriginalEnumMemberName = "OriginalEnumMemberName",
|
|
57
|
+
OriginalGenericName = "OriginalGenericName",
|
|
55
58
|
Predefined = "Predefined",
|
|
56
59
|
Protected = "Protected",
|
|
57
60
|
Synthetic = "Synthetic",
|
|
@@ -78,6 +81,9 @@ export interface IDLNode {
|
|
|
78
81
|
fileName?: string;
|
|
79
82
|
extendedAttributes?: IDLExtendedAttribute[];
|
|
80
83
|
documentation?: string;
|
|
84
|
+
nodeLocation?: Location;
|
|
85
|
+
nameLocation?: Location;
|
|
86
|
+
valueLocation?: Location;
|
|
81
87
|
}
|
|
82
88
|
export interface IDLFile extends IDLNode {
|
|
83
89
|
packageClause: string[];
|
|
@@ -223,6 +229,8 @@ type IDLNodeVisitorVoid = (node: IDLNode) => void;
|
|
|
223
229
|
type IDLNodeVisitorValue = (node: IDLNode) => () => void;
|
|
224
230
|
type IDLNodeVisitor = IDLNodeVisitorVoid | IDLNodeVisitorValue;
|
|
225
231
|
export declare function forEachChild(node: IDLNode, cbEnter: IDLNodeVisitor, cbLeave?: (entry: IDLNode) => void): void;
|
|
232
|
+
/** Updates tree in place! */
|
|
233
|
+
export declare function updateEachChild(node: IDLNode, op: (node: IDLNode) => IDLNode, cbLeave?: (entry: IDLNode) => void): IDLNode;
|
|
226
234
|
export declare function isNamedNode(type: IDLNode): type is IDLNamedNode;
|
|
227
235
|
export declare function forceAsNamedNode(type: IDLNode): IDLNamedNode;
|
|
228
236
|
export declare function isFile(node: IDLNode): node is IDLFile;
|