@mbler/mcx-core 0.0.5 → 0.0.6-alpha.r20260412.2

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 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;
@@ -218,7 +216,9 @@ declare const _default: {
218
216
  prop: typeof PropParser;
219
217
  };
220
218
 
221
- declare function mcxPlugn(opt: CompileOpt, output: transformCtx["output"]): Plugin;
219
+ declare function mcxPlugn(opt: CompileOpt & {
220
+ mcxLanguagePlugin?: any;
221
+ }, output: transformCtx["output"]): Plugin;
222
222
 
223
223
  declare class McxUtlis {
224
224
  /**
@@ -280,20 +280,20 @@ declare class CompileJS {
280
280
  declare function compileJSFn(code: string): JsCompileData;
281
281
  declare function compileMCXFn(mcxCode: string): MCXCompileData;
282
282
 
283
- type index$2_CompileError = CompileError;
284
- declare const index$2_CompileError: typeof CompileError;
285
- type index$2_CompileJS = CompileJS;
286
- declare const index$2_CompileJS: typeof CompileJS;
287
- type index$2_Context = Context;
288
- type index$2_JsCompileData = JsCompileData;
289
- declare const index$2_JsCompileData: typeof JsCompileData;
290
- type index$2_MCXCompileData = MCXCompileData;
291
- declare const index$2_MCXCompileData: typeof MCXCompileData;
292
- declare const index$2_compileJSFn: typeof compileJSFn;
293
- declare const index$2_compileMCXFn: typeof compileMCXFn;
294
- declare namespace index$2 {
295
- export { index$2_CompileError as CompileError, index$2_CompileJS as CompileJS, index$2_JsCompileData as JsCompileData, index$2_MCXCompileData as MCXCompileData, Utils as MCXNodeUtils, index$2_compileJSFn as compileJSFn, index$2_compileMCXFn as compileMCXFn };
296
- export type { index$2_Context as Context };
283
+ type index$1_CompileError = CompileError;
284
+ declare const index$1_CompileError: typeof CompileError;
285
+ type index$1_CompileJS = CompileJS;
286
+ declare const index$1_CompileJS: typeof CompileJS;
287
+ type index$1_Context = Context;
288
+ type index$1_JsCompileData = JsCompileData;
289
+ declare const index$1_JsCompileData: typeof JsCompileData;
290
+ type index$1_MCXCompileData = MCXCompileData;
291
+ declare const index$1_MCXCompileData: typeof MCXCompileData;
292
+ declare const index$1_compileJSFn: typeof compileJSFn;
293
+ declare const index$1_compileMCXFn: typeof compileMCXFn;
294
+ declare namespace index$1 {
295
+ 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 };
296
+ export type { index$1_Context as Context };
297
297
  }
298
298
 
299
299
  declare enum execESMMethod {
@@ -5040,77 +5040,30 @@ declare class ItemComponent {
5040
5040
 
5041
5041
  declare function compileComponent(compiledCode: MCXCompileData, ctx: transformCtx): Promise<void>;
5042
5042
 
5043
- type index$1_BlockComponent = BlockComponent;
5044
- declare const index$1_BlockComponent: typeof BlockComponent;
5045
- type index$1_EntityComponent = EntityComponent;
5046
- declare const index$1_EntityComponent: typeof EntityComponent;
5047
- type index$1_ItemComponent = ItemComponent;
5048
- declare const index$1_ItemComponent: typeof ItemComponent;
5049
- type index$1_RunScript = RunScript;
5050
- declare const index$1_RunScript: typeof RunScript;
5051
- declare const index$1_compileComponent: typeof compileComponent;
5052
- type index$1_execESMMethod = execESMMethod;
5053
- declare const index$1_execESMMethod: typeof execESMMethod;
5054
- declare const index$1_transformESMToCJS: typeof transformESMToCJS;
5055
- declare namespace index$1 {
5043
+ type index_BlockComponent = BlockComponent;
5044
+ declare const index_BlockComponent: typeof BlockComponent;
5045
+ type index_EntityComponent = EntityComponent;
5046
+ declare const index_EntityComponent: typeof EntityComponent;
5047
+ type index_ItemComponent = ItemComponent;
5048
+ declare const index_ItemComponent: typeof ItemComponent;
5049
+ type index_RunScript = RunScript;
5050
+ declare const index_RunScript: typeof RunScript;
5051
+ declare const index_compileComponent: typeof compileComponent;
5052
+ type index_execESMMethod = execESMMethod;
5053
+ declare const index_execESMMethod: typeof execESMMethod;
5054
+ declare const index_transformESMToCJS: typeof transformESMToCJS;
5055
+ declare namespace index {
5056
5056
  export {
5057
- index$1_BlockComponent as BlockComponent,
5058
- index$1_EntityComponent as EntityComponent,
5059
- index$1_ItemComponent as ItemComponent,
5060
- index$1_RunScript as RunScript,
5061
- index$1_compileComponent as compileComponent,
5062
- index$1_execESMMethod as execESMMethod,
5063
- index$1_transformESMToCJS as transformESMToCJS,
5057
+ index_BlockComponent as BlockComponent,
5058
+ index_EntityComponent as EntityComponent,
5059
+ index_ItemComponent as ItemComponent,
5060
+ index_RunScript as RunScript,
5061
+ index_compileComponent as compileComponent,
5062
+ index_execESMMethod as execESMMethod,
5063
+ index_transformESMToCJS as transformESMToCJS,
5064
5064
  };
5065
5065
  }
5066
5066
 
5067
5067
  declare function transform(code: MCXCompileData, cache: Map<string, MCXCompileData>, id: string, context: TransformPluginContext, opt: CompileOpt, output: transformCtx["output"]): Promise<string>;
5068
5068
 
5069
- interface ServiceScript {
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 };
5069
+ 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
@@ -4,7 +4,7 @@ var path = require('node:path');
4
4
  var t = require('@babel/types');
5
5
  var fs = require('node:fs/promises');
6
6
  var Parser$1 = require('@babel/parser');
7
- var ts = require('typescript');
7
+ var ts$1 = require('typescript');
8
8
  var generator = require('@babel/generator');
9
9
  var Module = require('node:module');
10
10
  var vm = require('node:vm');
@@ -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$1);
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$3 = {
576
+ var index$2 = {
576
577
  tag: McxAst,
577
578
  prop: PropParser
578
579
  };
@@ -1211,10 +1212,10 @@ class CompileMCX {
1211
1212
  const scriptNode = node.content.length == 0 ? "" : this.commonTagNodeContent(node);
1212
1213
  let code = scriptNode;
1213
1214
  if (node.arr.lang == "ts") {
1214
- code = ts.transpileModule(scriptNode, {
1215
+ code = ts$1.transpileModule(scriptNode, {
1215
1216
  compilerOptions: {
1216
- target: ts.ScriptTarget.ES2024,
1217
- module: ts.ModuleKind.ESNext,
1217
+ target: ts$1.ScriptTarget.ES2024,
1218
+ module: ts$1.ModuleKind.ESNext,
1218
1219
  },
1219
1220
  }).outputText;
1220
1221
  }
@@ -1356,7 +1357,7 @@ function compileMCXFn(mcxCode) {
1356
1357
  return compiler.getCompileData();
1357
1358
  }
1358
1359
 
1359
- var index$2 = /*#__PURE__*/Object.freeze({
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$1 = /*#__PURE__*/Object.freeze({
10692
+ var index = /*#__PURE__*/Object.freeze({
10692
10693
  __proto__: null,
10693
10694
  BlockComponent: BlockComponent,
10694
10695
  EntityComponent: EntityComponent,
@@ -10783,6 +10784,160 @@ async function transform(code, cache, id, context, opt, output) {
10783
10784
  return await _transform(transformContext);
10784
10785
  }
10785
10786
 
10787
+ let ts;
10788
+ class TsHook {
10789
+ static tsCompilerOptions;
10790
+ static compilerHost = null;
10791
+ static program = null;
10792
+ static fileCache = new Map();
10793
+ static mcxLanguagePlugin = null;
10794
+ static buildStart(context, opt) {
10795
+ this.fileCache.clear();
10796
+ if (!opt.ts) {
10797
+ ts = ts__namespace;
10798
+ }
10799
+ else {
10800
+ ts = opt.ts;
10801
+ }
10802
+ if (opt.mcxLanguagePlugin) {
10803
+ this.mcxLanguagePlugin = opt.mcxLanguagePlugin;
10804
+ context.debug(`[tsHook] MCX language plugin loaded for .mcx file support`);
10805
+ }
10806
+ const tsconfigPath = opt.tsconfigPath;
10807
+ if (tsconfigPath) {
10808
+ try {
10809
+ const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
10810
+ if (!configFile.error) {
10811
+ const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(tsconfigPath));
10812
+ this.tsCompilerOptions = { ...this.tsCompilerOptions, ...parsedConfig.options };
10813
+ }
10814
+ }
10815
+ catch (error) {
10816
+ context.warn(`Error reading tsconfig.json: ${error}`);
10817
+ }
10818
+ }
10819
+ if (!this.tsCompilerOptions) {
10820
+ throw new Error("[ts]: can't find tsconfig");
10821
+ }
10822
+ this.compilerHost = ts.createCompilerHost(this.tsCompilerOptions);
10823
+ const originalHost = this.compilerHost;
10824
+ this.compilerHost.getSourceFile = (fileName, languageVersion) => {
10825
+ const cachedContent = this.fileCache.get(fileName);
10826
+ if (cachedContent) {
10827
+ return ts.createSourceFile(fileName, cachedContent, languageVersion);
10828
+ }
10829
+ return originalHost.getSourceFile(fileName, languageVersion);
10830
+ };
10831
+ this.compilerHost.fileExists = (fileName) => {
10832
+ return this.fileCache.has(fileName) || originalHost.fileExists(fileName);
10833
+ };
10834
+ this.compilerHost.readFile = (fileName) => {
10835
+ const cachedContent = this.fileCache.get(fileName);
10836
+ if (cachedContent)
10837
+ return cachedContent;
10838
+ return originalHost.readFile(fileName);
10839
+ };
10840
+ this.program = ts.createProgram([], this.tsCompilerOptions, this.compilerHost);
10841
+ this.reportGlobalDiagnostics(context);
10842
+ }
10843
+ static reportGlobalDiagnostics(context) {
10844
+ if (!this.program || !ts)
10845
+ return;
10846
+ const diagnostics = ts.getPreEmitDiagnostics(this.program);
10847
+ diagnostics.forEach(diagnostic => {
10848
+ if (diagnostic.file) {
10849
+ const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
10850
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
10851
+ if (diagnostic.category === ts.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.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 (!ts || !this.tsCompilerOptions)
10869
+ throw new Error("[ts]: can't find ts module");
10870
+ if (!isTypeScript && !isJsx) {
10871
+ return code;
10872
+ }
10873
+ try {
10874
+ // 缓存当前文件内容
10875
+ this.fileCache.set(id, code);
10876
+ if (!this.program || !this.compilerHost) {
10877
+ // 如果没有预先创建的 compiler,创建临时的一个
10878
+ return this.fallbackTransform(context, code, id);
10879
+ }
10880
+ // 复用现有的程序,添加新文件
10881
+ const fileNames = [...new Set([...this.program.getSourceFiles().map(f => f.fileName), id])];
10882
+ this.program = ts.createProgram(fileNames, this.tsCompilerOptions, this.compilerHost);
10883
+ // 只检查当前文件的错误(避免重复报告全局错误)
10884
+ const sourceFile = this.program.getSourceFile(id);
10885
+ if (!sourceFile) {
10886
+ return this.fallbackTransform(context, code, id);
10887
+ }
10888
+ const diagnostics = [
10889
+ ...this.program.getSemanticDiagnostics(sourceFile),
10890
+ ...this.program.getSyntacticDiagnostics(sourceFile),
10891
+ ...this.program.getDeclarationDiagnostics(sourceFile)
10892
+ ];
10893
+ this.reportFileDiagnostics(context, diagnostics, id);
10894
+ return code;
10895
+ }
10896
+ catch (error) {
10897
+ context.error(`TypeScript transformation failed for ${id}: ${error}`);
10898
+ }
10899
+ }
10900
+ static fallbackTransform(context, code, id) {
10901
+ if (!this.tsCompilerOptions)
10902
+ throw new Error("[ts]: can't find tsconfig");
10903
+ try {
10904
+ ts.createSourceFile(id, code, this.tsCompilerOptions.target || ts.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.DiagnosticCategory.Error);
10915
+ const warnings = diagnostics.filter(d => d.category === ts.DiagnosticCategory.Warning);
10916
+ errors.forEach(diagnostic => {
10917
+ if (diagnostic.file) {
10918
+ const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
10919
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
10920
+ context.error(`${fileName} (${line + 1},${character + 1}): ${message}`);
10921
+ }
10922
+ });
10923
+ warnings.forEach(diagnostic => {
10924
+ if (diagnostic.file) {
10925
+ const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
10926
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
10927
+ context.warn(`${fileName} (${line + 1},${character + 1}): ${message}`);
10928
+ }
10929
+ });
10930
+ if (errors.length > 0) {
10931
+ throw new Error(`TypeScript compilation failed with ${errors.length} error(s) in ${fileName}`);
10932
+ }
10933
+ }
10934
+ static buildEnd(context) {
10935
+ this.compilerHost = null;
10936
+ this.program = null;
10937
+ this.fileCache.clear();
10938
+ }
10939
+ }
10940
+
10786
10941
  function mcxPlugn(opt, output) {
10787
10942
  let cache = new Map();
10788
10943
  return {
@@ -10815,6 +10970,7 @@ function mcxPlugn(opt, output) {
10815
10970
  transform: async function (code, id) {
10816
10971
  const magic = new MagicString(code);
10817
10972
  const ext = path.extname(id).slice(1);
10973
+ const tsRegex = /^.+?\.(ts|cts|mts|tsx|jsx)^/;
10818
10974
  if (ext == "mcx") {
10819
10975
  let compileData;
10820
10976
  try {
@@ -10832,21 +10988,31 @@ function mcxPlugn(opt, output) {
10832
10988
  });
10833
10989
  }
10834
10990
  this.error(String(err));
10991
+ return;
10835
10992
  }
10836
10993
  compileData.setFilePath(id);
10837
10994
  const compiledCode = await transform(compileData, cache, id, this, opt, output);
10838
10995
  return {
10839
10996
  code: compiledCode,
10840
- map: magic.generateMap({ hires: true, source: id }),
10997
+ map: opt.sourcemap ? magic.generateMap({ hires: true, source: id }) : void 0,
10998
+ };
10999
+ }
11000
+ else if (tsRegex.test(id)) {
11001
+ const compiledCode = await TsHook.transformTs(this, code, id, opt);
11002
+ return {
11003
+ code: compiledCode,
11004
+ map: opt.sourcemap ? magic.generateMap({ hires: true, source: id }) : void 0
10841
11005
  };
10842
11006
  }
10843
11007
  return null;
10844
11008
  },
10845
11009
  buildEnd() {
10846
11010
  cache.clear();
11011
+ TsHook.buildEnd(this);
10847
11012
  },
10848
11013
  buildStart() {
10849
11014
  cache = new Map();
11015
+ TsHook.buildStart(this, opt);
10850
11016
  }
10851
11017
  };
10852
11018
  }
@@ -10855,147 +11021,14 @@ var types = /*#__PURE__*/Object.freeze({
10855
11021
  __proto__: null
10856
11022
  });
10857
11023
 
10858
- class MCXVirtualCode {
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;
11024
+ exports.AST = index$2;
10991
11025
  exports.BlockComponent = BlockComponent;
10992
11026
  exports.ComponentType = types$1;
10993
11027
  exports.EntityComponent = EntityComponent;
10994
11028
  exports.ItemComponent = ItemComponent;
10995
11029
  exports.PUBTYPE = types;
10996
- exports.TSC = index;
10997
- exports.compile_component = index$1;
10998
- exports.compiler = index$2;
11030
+ exports.compile_component = index;
11031
+ exports.compiler = index$1;
10999
11032
  exports.plugin = mcxPlugn;
11000
11033
  exports.transform = transform;
11001
11034
  exports.utils = McxUtlis;