5
5
*/
6
6
import { _import , registerLoader } from "./module" ;
7
7
import { tagParser , textParser , expressionParser , ASTNode } from "./parser"
8
+ import { tokenizer , transpiler } from "./transpiler"
8
9
9
10
/**
10
11
* 驼峰转连字符
@@ -296,7 +297,7 @@ class AMEFComponent {
296
297
const tagName = tagContent . tagName ;
297
298
const isComponent = tagName . includes ( "-" ) ;
298
299
if ( isComponent ) { // 有连字符则判断为组件
299
- const component = this . $components [ tagName ] || AMEF . _global [ tagName ] ;
300
+ const component = this . $components [ tagName ] || AMEF . __component__ [ tagName ] ;
300
301
if ( ! component ) {
301
302
throw Error ( `未注册的组件: <${ tagName } ></${ tagName } >` ) ;
302
303
}
@@ -354,12 +355,14 @@ class AMEFComponent {
354
355
}
355
356
}
356
357
357
- const AMEF = new class {
358
+ class AMEFProto {
358
359
Component = AMEFComponent
359
360
import = _import
360
361
registerLoader = registerLoader
361
- _global : { [ key : string ] : AMEFComponentConfig } = { } ;
362
- __temp__ = { } ;
362
+ __component__ : { [ key : string ] : AMEFComponentConfig } = { }
363
+ __module__ = { }
364
+ tokenize = tokenizer
365
+ transpile = transpiler
363
366
364
367
/**
365
368
* 注册一个全局组件
@@ -372,14 +375,14 @@ const AMEF = new class {
372
375
if ( ! name ) {
373
376
console . error ( "请提供组件名称, 错误组件: " + component ) ;
374
377
return ;
375
- } else if ( name in this . _global ) {
378
+ } else if ( name in this . __component__ ) {
376
379
console . error ( `已经注册了同名组件, 错误组件: <${ name } ></${ name } >` ) ;
377
380
return ;
378
381
} else if ( ! name . includes ( "-" ) ) {
379
382
console . error ( `组件名称必须包含连字符, 错误组件: <${ name } ></${ name } >` ) ;
380
383
return ;
381
384
}
382
- this . _global [ name ] = component ;
385
+ this . __component__ [ name ] = component ;
383
386
}
384
387
385
388
/**
@@ -388,9 +391,13 @@ const AMEF = new class {
388
391
* @returns {AMEFComponent }
389
392
*/
390
393
instance ( name : string ) : AMEFComponent {
391
- return new AMEFComponent ( this . _global [ name ] ) ;
394
+ return new AMEFComponent ( this . __component__ [ name ] ) ;
392
395
}
393
396
}
394
397
398
+ declare global {
399
+ const AMEF : AMEFProto
400
+ }
401
+
395
402
// @ts -ignore
396
- window . AMEF = AMEF ;
403
+ window . AMEF = new AMEFProto ( ) ;
0 commit comments