@mbler/mcx-core 0.0.5 → 0.0.6-alpha.r20260412.1
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/index.d.ts +35 -84
- package/dist/index.js +177 -140
- package/dist/index.js.map +1 -1
- package/dist/types/compile-mcx/tsHook.d.ts +14 -0
- package/dist/types/index.d.ts +1 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,6 @@ import * as t from '@babel/types';
|
|
|
3
3
|
import { Expression, CallExpression, SpreadElement, ArgumentPlaceholder, ImportDeclaration, ExportNamedDeclaration, ExportAllDeclaration, ExportDefaultDeclaration } from '@babel/types';
|
|
4
4
|
import { CompileOpt } from '@mbler/mcx-types';
|
|
5
5
|
import * as Parser from '@babel/parser';
|
|
6
|
-
import * as ts from 'typescript';
|
|
7
|
-
import { VirtualCode, CodeMapping, LanguagePlugin } from '@volar/language-core';
|
|
8
6
|
|
|
9
7
|
interface callList {
|
|
10
8
|
source: Expression;
|
|
@@ -280,20 +278,20 @@ declare class CompileJS {
|
|
|
280
278
|
declare function compileJSFn(code: string): JsCompileData;
|
|
281
279
|
declare function compileMCXFn(mcxCode: string): MCXCompileData;
|
|
282
280
|
|
|
283
|
-
type index$
|
|
284
|
-
declare const index$
|
|
285
|
-
type index$
|
|
286
|
-
declare const index$
|
|
287
|
-
type index$
|
|
288
|
-
type index$
|
|
289
|
-
declare const index$
|
|
290
|
-
type index$
|
|
291
|
-
declare const index$
|
|
292
|
-
declare const index$
|
|
293
|
-
declare const index$
|
|
294
|
-
declare namespace index$
|
|
295
|
-
export { index$
|
|
296
|
-
export type { index$
|
|
281
|
+
type index$1_CompileError = CompileError;
|
|
282
|
+
declare const index$1_CompileError: typeof CompileError;
|
|
283
|
+
type index$1_CompileJS = CompileJS;
|
|
284
|
+
declare const index$1_CompileJS: typeof CompileJS;
|
|
285
|
+
type index$1_Context = Context;
|
|
286
|
+
type index$1_JsCompileData = JsCompileData;
|
|
287
|
+
declare const index$1_JsCompileData: typeof JsCompileData;
|
|
288
|
+
type index$1_MCXCompileData = MCXCompileData;
|
|
289
|
+
declare const index$1_MCXCompileData: typeof MCXCompileData;
|
|
290
|
+
declare const index$1_compileJSFn: typeof compileJSFn;
|
|
291
|
+
declare const index$1_compileMCXFn: typeof compileMCXFn;
|
|
292
|
+
declare namespace index$1 {
|
|
293
|
+
export { index$1_CompileError as CompileError, index$1_CompileJS as CompileJS, index$1_JsCompileData as JsCompileData, index$1_MCXCompileData as MCXCompileData, Utils as MCXNodeUtils, index$1_compileJSFn as compileJSFn, index$1_compileMCXFn as compileMCXFn };
|
|
294
|
+
export type { index$1_Context as Context };
|
|
297
295
|
}
|
|
298
296
|
|
|
299
297
|
declare enum execESMMethod {
|
|
@@ -5040,77 +5038,30 @@ declare class ItemComponent {
|
|
|
5040
5038
|
|
|
5041
5039
|
declare function compileComponent(compiledCode: MCXCompileData, ctx: transformCtx): Promise<void>;
|
|
5042
5040
|
|
|
5043
|
-
type
|
|
5044
|
-
declare const
|
|
5045
|
-
type
|
|
5046
|
-
declare const
|
|
5047
|
-
type
|
|
5048
|
-
declare const
|
|
5049
|
-
type
|
|
5050
|
-
declare const
|
|
5051
|
-
declare const
|
|
5052
|
-
type
|
|
5053
|
-
declare const
|
|
5054
|
-
declare const
|
|
5055
|
-
declare namespace index
|
|
5041
|
+
type index_BlockComponent = BlockComponent;
|
|
5042
|
+
declare const index_BlockComponent: typeof BlockComponent;
|
|
5043
|
+
type index_EntityComponent = EntityComponent;
|
|
5044
|
+
declare const index_EntityComponent: typeof EntityComponent;
|
|
5045
|
+
type index_ItemComponent = ItemComponent;
|
|
5046
|
+
declare const index_ItemComponent: typeof ItemComponent;
|
|
5047
|
+
type index_RunScript = RunScript;
|
|
5048
|
+
declare const index_RunScript: typeof RunScript;
|
|
5049
|
+
declare const index_compileComponent: typeof compileComponent;
|
|
5050
|
+
type index_execESMMethod = execESMMethod;
|
|
5051
|
+
declare const index_execESMMethod: typeof execESMMethod;
|
|
5052
|
+
declare const index_transformESMToCJS: typeof transformESMToCJS;
|
|
5053
|
+
declare namespace index {
|
|
5056
5054
|
export {
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5055
|
+
index_BlockComponent as BlockComponent,
|
|
5056
|
+
index_EntityComponent as EntityComponent,
|
|
5057
|
+
index_ItemComponent as ItemComponent,
|
|
5058
|
+
index_RunScript as RunScript,
|
|
5059
|
+
index_compileComponent as compileComponent,
|
|
5060
|
+
index_execESMMethod as execESMMethod,
|
|
5061
|
+
index_transformESMToCJS as transformESMToCJS,
|
|
5064
5062
|
};
|
|
5065
5063
|
}
|
|
5066
5064
|
|
|
5067
5065
|
declare function transform(code: MCXCompileData, cache: Map<string, MCXCompileData>, id: string, context: TransformPluginContext, opt: CompileOpt, output: transformCtx["output"]): Promise<string>;
|
|
5068
5066
|
|
|
5069
|
-
|
|
5070
|
-
code: VirtualCode;
|
|
5071
|
-
scriptKind: ts.ScriptKind;
|
|
5072
|
-
preventLeadingOffset: boolean;
|
|
5073
|
-
extension: string;
|
|
5074
|
-
}
|
|
5075
|
-
interface TypeScriptLanguagePlugin {
|
|
5076
|
-
getServiceScript(virtualCode: VirtualCode): ServiceScript | undefined;
|
|
5077
|
-
extraFileExtensions: {
|
|
5078
|
-
extension: string;
|
|
5079
|
-
isMixedContent: boolean;
|
|
5080
|
-
scriptKind: ts.ScriptKind;
|
|
5081
|
-
}[];
|
|
5082
|
-
}
|
|
5083
|
-
interface MCXLanguagePlugin extends LanguagePlugin<string> {
|
|
5084
|
-
typescript: TypeScriptLanguagePlugin;
|
|
5085
|
-
}
|
|
5086
|
-
declare class MCXVirtualCode implements VirtualCode {
|
|
5087
|
-
id: string;
|
|
5088
|
-
languageId: string;
|
|
5089
|
-
mappings: CodeMapping[];
|
|
5090
|
-
embeddedCodes: VirtualCode[];
|
|
5091
|
-
snapshot: ts.IScriptSnapshot;
|
|
5092
|
-
constructor(snapshot: ts.IScriptSnapshot);
|
|
5093
|
-
private extractScriptContent;
|
|
5094
|
-
private calculateScriptOffset;
|
|
5095
|
-
}
|
|
5096
|
-
/**
|
|
5097
|
-
* 创建 MCX 语言插件
|
|
5098
|
-
* @param tsModule TypeScript
|
|
5099
|
-
* @returns MCXLanguagePlugin
|
|
5100
|
-
*/
|
|
5101
|
-
declare function createMCXLanguagePlugin(tsModule: typeof ts): MCXLanguagePlugin;
|
|
5102
|
-
declare function createMCXVirtualCode(snapshot: ts.IScriptSnapshot): VirtualCode;
|
|
5103
|
-
|
|
5104
|
-
type index_MCXVirtualCode = MCXVirtualCode;
|
|
5105
|
-
declare const index_MCXVirtualCode: typeof MCXVirtualCode;
|
|
5106
|
-
declare const index_createMCXLanguagePlugin: typeof createMCXLanguagePlugin;
|
|
5107
|
-
declare const index_createMCXVirtualCode: typeof createMCXVirtualCode;
|
|
5108
|
-
declare namespace index {
|
|
5109
|
-
export {
|
|
5110
|
-
index_MCXVirtualCode as MCXVirtualCode,
|
|
5111
|
-
index_createMCXLanguagePlugin as createMCXLanguagePlugin,
|
|
5112
|
-
index_createMCXVirtualCode as createMCXVirtualCode,
|
|
5113
|
-
};
|
|
5114
|
-
}
|
|
5115
|
-
|
|
5116
|
-
export { _default as AST, BlockComponent, types as ComponentType, EntityComponent, ItemComponent, types$1 as PUBTYPE, index as TSC, index$1 as compile_component, index$2 as compiler, mcxPlugn as plugin, transform, McxUtlis as utils };
|
|
5067
|
+
export { _default as AST, BlockComponent, types as ComponentType, EntityComponent, ItemComponent, types$1 as PUBTYPE, index as compile_component, index$1 as compiler, mcxPlugn as plugin, transform, McxUtlis as utils };
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
|
32
32
|
var t__namespace = /*#__PURE__*/_interopNamespaceDefault(t);
|
|
33
33
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
34
34
|
var Parser__namespace = /*#__PURE__*/_interopNamespaceDefault(Parser$1);
|
|
35
|
+
var ts__namespace = /*#__PURE__*/_interopNamespaceDefault(ts);
|
|
35
36
|
var generator__namespace = /*#__PURE__*/_interopNamespaceDefault(generator);
|
|
36
37
|
var Module__namespace = /*#__PURE__*/_interopNamespaceDefault(Module);
|
|
37
38
|
var vm__namespace = /*#__PURE__*/_interopNamespaceDefault(vm);
|
|
@@ -572,7 +573,7 @@ function PropParser(code) {
|
|
|
572
573
|
return Array.from(lexer.tokenize());
|
|
573
574
|
}
|
|
574
575
|
|
|
575
|
-
var index$
|
|
576
|
+
var index$2 = {
|
|
576
577
|
tag: McxAst,
|
|
577
578
|
prop: PropParser
|
|
578
579
|
};
|
|
@@ -1356,7 +1357,7 @@ function compileMCXFn(mcxCode) {
|
|
|
1356
1357
|
return compiler.getCompileData();
|
|
1357
1358
|
}
|
|
1358
1359
|
|
|
1359
|
-
var index$
|
|
1360
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
1360
1361
|
__proto__: null,
|
|
1361
1362
|
CompileError: CompileError,
|
|
1362
1363
|
CompileJS: CompileJS,
|
|
@@ -10688,7 +10689,7 @@ async function compileComponent(compiledCode, ctx) {
|
|
|
10688
10689
|
}
|
|
10689
10690
|
}
|
|
10690
10691
|
|
|
10691
|
-
var index
|
|
10692
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
10692
10693
|
__proto__: null,
|
|
10693
10694
|
BlockComponent: BlockComponent,
|
|
10694
10695
|
EntityComponent: EntityComponent,
|
|
@@ -10783,6 +10784,164 @@ async function transform(code, cache, id, context, opt, output) {
|
|
|
10783
10784
|
return await _transform(transformContext);
|
|
10784
10785
|
}
|
|
10785
10786
|
|
|
10787
|
+
class TsHook {
|
|
10788
|
+
static tsCompilerOptions = {
|
|
10789
|
+
target: ts__namespace.ScriptTarget.ESNext,
|
|
10790
|
+
module: ts__namespace.ModuleKind.ESNext,
|
|
10791
|
+
jsx: ts__namespace.JsxEmit.Preserve,
|
|
10792
|
+
allowSyntheticDefaultImports: true,
|
|
10793
|
+
esModuleInterop: true,
|
|
10794
|
+
skipLibCheck: true,
|
|
10795
|
+
strict: false
|
|
10796
|
+
};
|
|
10797
|
+
static compilerHost = null;
|
|
10798
|
+
static program = null;
|
|
10799
|
+
static fileCache = new Map();
|
|
10800
|
+
static buildStart(context, opt) {
|
|
10801
|
+
// 清空缓存
|
|
10802
|
+
this.fileCache.clear();
|
|
10803
|
+
// 读取 tsconfig.json
|
|
10804
|
+
const tsconfigPath = opt.tsconfigPath;
|
|
10805
|
+
if (tsconfigPath) {
|
|
10806
|
+
try {
|
|
10807
|
+
const configFile = ts__namespace.readConfigFile(tsconfigPath, ts__namespace.sys.readFile);
|
|
10808
|
+
if (!configFile.error) {
|
|
10809
|
+
const parsedConfig = ts__namespace.parseJsonConfigFileContent(configFile.config, ts__namespace.sys, path.dirname(tsconfigPath));
|
|
10810
|
+
this.tsCompilerOptions = { ...this.tsCompilerOptions, ...parsedConfig.options };
|
|
10811
|
+
}
|
|
10812
|
+
}
|
|
10813
|
+
catch (error) {
|
|
10814
|
+
context.warn(`Error reading tsconfig.json: ${error}`);
|
|
10815
|
+
}
|
|
10816
|
+
}
|
|
10817
|
+
// 创建可复用的 compilerHost
|
|
10818
|
+
this.compilerHost = ts__namespace.createCompilerHost(this.tsCompilerOptions);
|
|
10819
|
+
// 重写方法以支持动态文件内容
|
|
10820
|
+
const originalHost = this.compilerHost;
|
|
10821
|
+
this.compilerHost.getSourceFile = (fileName, languageVersion) => {
|
|
10822
|
+
const cachedContent = this.fileCache.get(fileName);
|
|
10823
|
+
if (cachedContent) {
|
|
10824
|
+
return ts__namespace.createSourceFile(fileName, cachedContent, languageVersion);
|
|
10825
|
+
}
|
|
10826
|
+
return originalHost.getSourceFile(fileName, languageVersion);
|
|
10827
|
+
};
|
|
10828
|
+
this.compilerHost.fileExists = (fileName) => {
|
|
10829
|
+
return this.fileCache.has(fileName) || originalHost.fileExists(fileName);
|
|
10830
|
+
};
|
|
10831
|
+
this.compilerHost.readFile = (fileName) => {
|
|
10832
|
+
const cachedContent = this.fileCache.get(fileName);
|
|
10833
|
+
if (cachedContent)
|
|
10834
|
+
return cachedContent;
|
|
10835
|
+
return originalHost.readFile(fileName);
|
|
10836
|
+
};
|
|
10837
|
+
// 创建空的初始程序
|
|
10838
|
+
this.program = ts__namespace.createProgram([], this.tsCompilerOptions, this.compilerHost);
|
|
10839
|
+
// 提前检查并报告所有类型的错误
|
|
10840
|
+
this.reportGlobalDiagnostics(context);
|
|
10841
|
+
}
|
|
10842
|
+
static reportGlobalDiagnostics(context) {
|
|
10843
|
+
if (!this.program)
|
|
10844
|
+
return;
|
|
10845
|
+
// 获取全局诊断信息(比如 tsconfig 错误、类型声明错误等)
|
|
10846
|
+
const diagnostics = ts__namespace.getPreEmitDiagnostics(this.program);
|
|
10847
|
+
diagnostics.forEach(diagnostic => {
|
|
10848
|
+
if (diagnostic.file) {
|
|
10849
|
+
const { line, character } = ts__namespace.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
10850
|
+
const message = ts__namespace.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
10851
|
+
if (diagnostic.category === ts__namespace.DiagnosticCategory.Error) {
|
|
10852
|
+
context.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
|
10853
|
+
}
|
|
10854
|
+
else {
|
|
10855
|
+
context.warn(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
|
10856
|
+
}
|
|
10857
|
+
}
|
|
10858
|
+
else {
|
|
10859
|
+
const message = ts__namespace.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
10860
|
+
context.warn(`TypeScript: ${message}`);
|
|
10861
|
+
}
|
|
10862
|
+
});
|
|
10863
|
+
}
|
|
10864
|
+
static async transformTs(context, code, id, opt) {
|
|
10865
|
+
const ext = id.slice(id.lastIndexOf('.'));
|
|
10866
|
+
const isTypeScript = ['.ts', '.tsx', '.cts', '.mts'].includes(ext);
|
|
10867
|
+
const isJsx = ['.tsx', '.jsx'].includes(ext);
|
|
10868
|
+
if (!isTypeScript && !isJsx) {
|
|
10869
|
+
return code;
|
|
10870
|
+
}
|
|
10871
|
+
try {
|
|
10872
|
+
// 缓存当前文件内容
|
|
10873
|
+
this.fileCache.set(id, code);
|
|
10874
|
+
if (!this.program || !this.compilerHost) {
|
|
10875
|
+
// 如果没有预先创建的 compiler,创建临时的一个
|
|
10876
|
+
return this.fallbackTransform(context, code, id);
|
|
10877
|
+
}
|
|
10878
|
+
// 复用现有的程序,添加新文件
|
|
10879
|
+
const fileNames = [...new Set([...this.program.getSourceFiles().map(f => f.fileName), id])];
|
|
10880
|
+
this.program = ts__namespace.createProgram(fileNames, this.tsCompilerOptions, this.compilerHost);
|
|
10881
|
+
// 只检查当前文件的错误(避免重复报告全局错误)
|
|
10882
|
+
const sourceFile = this.program.getSourceFile(id);
|
|
10883
|
+
if (!sourceFile) {
|
|
10884
|
+
return this.fallbackTransform(context, code, id);
|
|
10885
|
+
}
|
|
10886
|
+
const diagnostics = [
|
|
10887
|
+
...this.program.getSemanticDiagnostics(sourceFile),
|
|
10888
|
+
...this.program.getSyntacticDiagnostics(sourceFile),
|
|
10889
|
+
...this.program.getDeclarationDiagnostics(sourceFile)
|
|
10890
|
+
];
|
|
10891
|
+
// 报告具体文件的错误
|
|
10892
|
+
this.reportFileDiagnostics(context, diagnostics, id);
|
|
10893
|
+
// TypeScript 文件由 Rollup 的插件处理,这里只做类型检查
|
|
10894
|
+
return code;
|
|
10895
|
+
}
|
|
10896
|
+
catch (error) {
|
|
10897
|
+
context.error(`TypeScript transformation failed for ${id}: ${error}`);
|
|
10898
|
+
throw error;
|
|
10899
|
+
}
|
|
10900
|
+
}
|
|
10901
|
+
static fallbackTransform(context, code, id) {
|
|
10902
|
+
// 简单的回退实现 - 只做基本检查
|
|
10903
|
+
try {
|
|
10904
|
+
ts__namespace.createSourceFile(id, code, this.tsCompilerOptions.target || ts__namespace.ScriptTarget.ESNext);
|
|
10905
|
+
}
|
|
10906
|
+
catch (error) {
|
|
10907
|
+
context.error(`Failed to parse TypeScript file ${id}: ${error}`);
|
|
10908
|
+
}
|
|
10909
|
+
return code;
|
|
10910
|
+
}
|
|
10911
|
+
static reportFileDiagnostics(context, diagnostics, fileName) {
|
|
10912
|
+
if (diagnostics.length === 0)
|
|
10913
|
+
return;
|
|
10914
|
+
const errors = diagnostics.filter(d => d.category === ts__namespace.DiagnosticCategory.Error);
|
|
10915
|
+
const warnings = diagnostics.filter(d => d.category === ts__namespace.DiagnosticCategory.Warning);
|
|
10916
|
+
// 优先报告错误
|
|
10917
|
+
errors.forEach(diagnostic => {
|
|
10918
|
+
if (diagnostic.file) {
|
|
10919
|
+
const { line, character } = ts__namespace.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
10920
|
+
const message = ts__namespace.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
10921
|
+
context.error(`${fileName} (${line + 1},${character + 1}): ${message}`);
|
|
10922
|
+
}
|
|
10923
|
+
});
|
|
10924
|
+
// 报告警告
|
|
10925
|
+
warnings.forEach(diagnostic => {
|
|
10926
|
+
if (diagnostic.file) {
|
|
10927
|
+
const { line, character } = ts__namespace.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
10928
|
+
const message = ts__namespace.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
10929
|
+
context.warn(`${fileName} (${line + 1},${character + 1}): ${message}`);
|
|
10930
|
+
}
|
|
10931
|
+
});
|
|
10932
|
+
// 如果有错误,抛出异常停止处理
|
|
10933
|
+
if (errors.length > 0) {
|
|
10934
|
+
throw new Error(`TypeScript compilation failed with ${errors.length} error(s) in ${fileName}`);
|
|
10935
|
+
}
|
|
10936
|
+
}
|
|
10937
|
+
static buildEnd(context) {
|
|
10938
|
+
// 清理编译器和缓存
|
|
10939
|
+
this.compilerHost = null;
|
|
10940
|
+
this.program = null;
|
|
10941
|
+
this.fileCache.clear();
|
|
10942
|
+
}
|
|
10943
|
+
}
|
|
10944
|
+
|
|
10786
10945
|
function mcxPlugn(opt, output) {
|
|
10787
10946
|
let cache = new Map();
|
|
10788
10947
|
return {
|
|
@@ -10815,6 +10974,7 @@ function mcxPlugn(opt, output) {
|
|
|
10815
10974
|
transform: async function (code, id) {
|
|
10816
10975
|
const magic = new MagicString(code);
|
|
10817
10976
|
const ext = path.extname(id).slice(1);
|
|
10977
|
+
const tsRegex = /^.+?\.(ts|cts|mts|tsx|jsx)^/;
|
|
10818
10978
|
if (ext == "mcx") {
|
|
10819
10979
|
let compileData;
|
|
10820
10980
|
try {
|
|
@@ -10832,21 +10992,31 @@ function mcxPlugn(opt, output) {
|
|
|
10832
10992
|
});
|
|
10833
10993
|
}
|
|
10834
10994
|
this.error(String(err));
|
|
10995
|
+
return;
|
|
10835
10996
|
}
|
|
10836
10997
|
compileData.setFilePath(id);
|
|
10837
10998
|
const compiledCode = await transform(compileData, cache, id, this, opt, output);
|
|
10838
10999
|
return {
|
|
10839
11000
|
code: compiledCode,
|
|
10840
|
-
map: magic.generateMap({ hires: true, source: id }),
|
|
11001
|
+
map: opt.sourcemap ? magic.generateMap({ hires: true, source: id }) : void 0,
|
|
11002
|
+
};
|
|
11003
|
+
}
|
|
11004
|
+
else if (tsRegex.test(id)) {
|
|
11005
|
+
const compiledCode = await TsHook.transformTs(this, code, id, opt);
|
|
11006
|
+
return {
|
|
11007
|
+
code: compiledCode,
|
|
11008
|
+
map: opt.sourcemap ? magic.generateMap({ hires: true, source: id }) : void 0
|
|
10841
11009
|
};
|
|
10842
11010
|
}
|
|
10843
11011
|
return null;
|
|
10844
11012
|
},
|
|
10845
11013
|
buildEnd() {
|
|
10846
11014
|
cache.clear();
|
|
11015
|
+
TsHook.buildEnd(this);
|
|
10847
11016
|
},
|
|
10848
11017
|
buildStart() {
|
|
10849
11018
|
cache = new Map();
|
|
11019
|
+
TsHook.buildStart(this, opt);
|
|
10850
11020
|
}
|
|
10851
11021
|
};
|
|
10852
11022
|
}
|
|
@@ -10855,147 +11025,14 @@ var types = /*#__PURE__*/Object.freeze({
|
|
|
10855
11025
|
__proto__: null
|
|
10856
11026
|
});
|
|
10857
11027
|
|
|
10858
|
-
|
|
10859
|
-
id = 'root';
|
|
10860
|
-
languageId = 'mcx';
|
|
10861
|
-
mappings;
|
|
10862
|
-
embeddedCodes = [];
|
|
10863
|
-
snapshot;
|
|
10864
|
-
constructor(snapshot) {
|
|
10865
|
-
this.snapshot = snapshot;
|
|
10866
|
-
const content = snapshot.getText(0, snapshot.getLength());
|
|
10867
|
-
this.mappings = [{
|
|
10868
|
-
sourceOffsets: [0],
|
|
10869
|
-
generatedOffsets: [0],
|
|
10870
|
-
lengths: [snapshot.getLength()],
|
|
10871
|
-
data: {
|
|
10872
|
-
verification: false,
|
|
10873
|
-
completion: false,
|
|
10874
|
-
semantic: false,
|
|
10875
|
-
navigation: false,
|
|
10876
|
-
structure: false,
|
|
10877
|
-
format: false,
|
|
10878
|
-
}
|
|
10879
|
-
}];
|
|
10880
|
-
const embeddedCode = this.extractScriptContent(content);
|
|
10881
|
-
if (embeddedCode) {
|
|
10882
|
-
this.embeddedCodes.push(embeddedCode);
|
|
10883
|
-
}
|
|
10884
|
-
}
|
|
10885
|
-
extractScriptContent(content) {
|
|
10886
|
-
try {
|
|
10887
|
-
const compiled = compileMCXFn(content);
|
|
10888
|
-
const scriptContent = compiled.strLoc.script;
|
|
10889
|
-
if (!scriptContent || scriptContent.trim() === '') {
|
|
10890
|
-
return null;
|
|
10891
|
-
}
|
|
10892
|
-
const scriptNode = compiled.raw.find(node => node.name === 'script');
|
|
10893
|
-
if (!scriptNode) {
|
|
10894
|
-
return null;
|
|
10895
|
-
}
|
|
10896
|
-
const isTypeScript = scriptNode.arr?.lang === 'ts';
|
|
10897
|
-
const sourceOffset = this.calculateScriptOffset(content, scriptNode);
|
|
10898
|
-
const scriptSnapshot = {
|
|
10899
|
-
getText: (start, end) => scriptContent.slice(start, end),
|
|
10900
|
-
getLength: () => scriptContent.length,
|
|
10901
|
-
getChangeRange: () => undefined,
|
|
10902
|
-
};
|
|
10903
|
-
return {
|
|
10904
|
-
id: 'script',
|
|
10905
|
-
languageId: isTypeScript ? 'typescript' : 'javascript',
|
|
10906
|
-
snapshot: scriptSnapshot,
|
|
10907
|
-
mappings: [{
|
|
10908
|
-
sourceOffsets: [sourceOffset],
|
|
10909
|
-
generatedOffsets: [0],
|
|
10910
|
-
lengths: [scriptContent.length],
|
|
10911
|
-
data: {
|
|
10912
|
-
verification: true,
|
|
10913
|
-
completion: true,
|
|
10914
|
-
semantic: true,
|
|
10915
|
-
navigation: true,
|
|
10916
|
-
structure: true,
|
|
10917
|
-
format: true,
|
|
10918
|
-
}
|
|
10919
|
-
}],
|
|
10920
|
-
embeddedCodes: [],
|
|
10921
|
-
};
|
|
10922
|
-
}
|
|
10923
|
-
catch {
|
|
10924
|
-
return null;
|
|
10925
|
-
}
|
|
10926
|
-
}
|
|
10927
|
-
calculateScriptOffset(content, scriptNode) {
|
|
10928
|
-
const startTagData = scriptNode.start.data;
|
|
10929
|
-
const startTagIndex = content.indexOf(startTagData);
|
|
10930
|
-
if (startTagIndex === -1) {
|
|
10931
|
-
return 0;
|
|
10932
|
-
}
|
|
10933
|
-
return startTagIndex + startTagData.length;
|
|
10934
|
-
}
|
|
10935
|
-
}
|
|
10936
|
-
/**
|
|
10937
|
-
* 创建 MCX 语言插件
|
|
10938
|
-
* @param tsModule TypeScript
|
|
10939
|
-
* @returns MCXLanguagePlugin
|
|
10940
|
-
*/
|
|
10941
|
-
function createMCXLanguagePlugin(tsModule) {
|
|
10942
|
-
return {
|
|
10943
|
-
getLanguageId(scriptId) {
|
|
10944
|
-
if (scriptId.endsWith('.mcx')) {
|
|
10945
|
-
return 'mcx';
|
|
10946
|
-
}
|
|
10947
|
-
return undefined;
|
|
10948
|
-
},
|
|
10949
|
-
createVirtualCode(_scriptId, languageId, snapshot) {
|
|
10950
|
-
if (languageId === 'mcx') {
|
|
10951
|
-
return new MCXVirtualCode(snapshot);
|
|
10952
|
-
}
|
|
10953
|
-
return undefined;
|
|
10954
|
-
},
|
|
10955
|
-
typescript: {
|
|
10956
|
-
extraFileExtensions: [
|
|
10957
|
-
{
|
|
10958
|
-
extension: 'mcx',
|
|
10959
|
-
isMixedContent: true,
|
|
10960
|
-
scriptKind: tsModule.ScriptKind.JS,
|
|
10961
|
-
},
|
|
10962
|
-
],
|
|
10963
|
-
getServiceScript(virtualCode) {
|
|
10964
|
-
const scriptCode = virtualCode.embeddedCodes?.find(code => code.languageId === 'typescript' || code.languageId === 'javascript');
|
|
10965
|
-
if (!scriptCode) {
|
|
10966
|
-
return undefined;
|
|
10967
|
-
}
|
|
10968
|
-
const isTypeScript = scriptCode.languageId === 'typescript';
|
|
10969
|
-
return {
|
|
10970
|
-
code: scriptCode,
|
|
10971
|
-
scriptKind: isTypeScript ? tsModule.ScriptKind.TS : tsModule.ScriptKind.JS,
|
|
10972
|
-
preventLeadingOffset: false,
|
|
10973
|
-
extension: isTypeScript ? '.ts' : '.js',
|
|
10974
|
-
};
|
|
10975
|
-
},
|
|
10976
|
-
},
|
|
10977
|
-
};
|
|
10978
|
-
}
|
|
10979
|
-
function createMCXVirtualCode(snapshot) {
|
|
10980
|
-
return new MCXVirtualCode(snapshot);
|
|
10981
|
-
}
|
|
10982
|
-
|
|
10983
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
10984
|
-
__proto__: null,
|
|
10985
|
-
MCXVirtualCode: MCXVirtualCode,
|
|
10986
|
-
createMCXLanguagePlugin: createMCXLanguagePlugin,
|
|
10987
|
-
createMCXVirtualCode: createMCXVirtualCode
|
|
10988
|
-
});
|
|
10989
|
-
|
|
10990
|
-
exports.AST = index$3;
|
|
11028
|
+
exports.AST = index$2;
|
|
10991
11029
|
exports.BlockComponent = BlockComponent;
|
|
10992
11030
|
exports.ComponentType = types$1;
|
|
10993
11031
|
exports.EntityComponent = EntityComponent;
|
|
10994
11032
|
exports.ItemComponent = ItemComponent;
|
|
10995
11033
|
exports.PUBTYPE = types;
|
|
10996
|
-
exports.
|
|
10997
|
-
exports.
|
|
10998
|
-
exports.compiler = index$2;
|
|
11034
|
+
exports.compile_component = index;
|
|
11035
|
+
exports.compiler = index$1;
|
|
10999
11036
|
exports.plugin = mcxPlugn;
|
|
11000
11037
|
exports.transform = transform;
|
|
11001
11038
|
exports.utils = McxUtlis;
|