Skip to content

Commit 6a30393

Browse files
committed
expose transpiler
1 parent ccfdae6 commit 6a30393

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/AMEF.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
import { _import, registerLoader } from "./module";
77
import { tagParser, textParser, expressionParser, ASTNode } from "./parser"
8+
import { tokenizer, transpiler } from "./transpiler"
89

910
/**
1011
* 驼峰转连字符
@@ -296,7 +297,7 @@ class AMEFComponent {
296297
const tagName = tagContent.tagName;
297298
const isComponent = tagName.includes("-");
298299
if (isComponent) { // 有连字符则判断为组件
299-
const component = this.$components[tagName] || AMEF._global[tagName];
300+
const component = this.$components[tagName] || AMEF.__component__[tagName];
300301
if (!component) {
301302
throw Error(`未注册的组件: <${tagName}></${tagName}>`);
302303
}
@@ -354,12 +355,14 @@ class AMEFComponent {
354355
}
355356
}
356357

357-
const AMEF = new class {
358+
class AMEFProto {
358359
Component = AMEFComponent
359360
import = _import
360361
registerLoader = registerLoader
361-
_global: { [key: string]: AMEFComponentConfig } = {};
362-
__temp__ = {};
362+
__component__: { [key: string]: AMEFComponentConfig } = {}
363+
__module__ = {}
364+
tokenize = tokenizer
365+
transpile = transpiler
363366

364367
/**
365368
* 注册一个全局组件
@@ -372,14 +375,14 @@ const AMEF = new class {
372375
if (!name) {
373376
console.error("请提供组件名称, 错误组件: " + component);
374377
return;
375-
} else if (name in this._global) {
378+
} else if (name in this.__component__) {
376379
console.error(`已经注册了同名组件, 错误组件: <${name}></${name}>`);
377380
return;
378381
} else if (!name.includes("-")) {
379382
console.error(`组件名称必须包含连字符, 错误组件: <${name}></${name}>`);
380383
return;
381384
}
382-
this._global[name] = component;
385+
this.__component__[name] = component;
383386
}
384387

385388
/**
@@ -388,9 +391,13 @@ const AMEF = new class {
388391
* @returns {AMEFComponent}
389392
*/
390393
instance(name: string): AMEFComponent {
391-
return new AMEFComponent(this._global[name]);
394+
return new AMEFComponent(this.__component__[name]);
392395
}
393396
}
394397

398+
declare global {
399+
const AMEF: AMEFProto
400+
}
401+
395402
// @ts-ignore
396-
window.AMEF = AMEF;
403+
window.AMEF = new AMEFProto();

0 commit comments

Comments
 (0)