@@ -5,15 +5,15 @@ import { DEFAULT_STYLE_MODE, augmentDiagnosticWithNode, buildError, validateComp
5
5
import { CLASS_DECORATORS_TO_REMOVE } from '../remove-stencil-import' ;
6
6
7
7
8
- export function componentDecoratorToStatic ( config : d . Config , diagnostics : d . Diagnostic [ ] , cmpNode : ts . ClassDeclaration , newMembers : ts . ClassElement [ ] , componentDecorator : ts . Decorator ) {
8
+ export function componentDecoratorToStatic ( config : d . Config , typeChecker : ts . TypeChecker , diagnostics : d . Diagnostic [ ] , cmpNode : ts . ClassDeclaration , newMembers : ts . ClassElement [ ] , componentDecorator : ts . Decorator ) {
9
9
removeDecorators ( cmpNode , CLASS_DECORATORS_TO_REMOVE ) ;
10
10
11
11
const [ componentOptions ] = getDeclarationParameters < d . ComponentOptions > ( componentDecorator ) ;
12
12
if ( ! componentOptions ) {
13
13
return ;
14
14
}
15
15
16
- if ( ! validateComponent ( config , diagnostics , componentOptions , cmpNode , componentDecorator ) ) {
16
+ if ( ! validateComponent ( config , diagnostics , typeChecker , componentOptions , cmpNode , componentDecorator ) ) {
17
17
return ;
18
18
}
19
19
@@ -67,9 +67,10 @@ export function componentDecoratorToStatic(config: d.Config, diagnostics: d.Diag
67
67
newMembers . push ( createStaticGetter ( 'styles' , convertValueToLiteral ( styles ) ) ) ;
68
68
}
69
69
}
70
+
70
71
}
71
72
72
- function validateComponent ( config : d . Config , diagnostics : d . Diagnostic [ ] , componentOptions : d . ComponentOptions , cmpNode : ts . ClassDeclaration , componentDecorator : ts . Node ) {
73
+ function validateComponent ( config : d . Config , diagnostics : d . Diagnostic [ ] , typeChecker : ts . TypeChecker , componentOptions : d . ComponentOptions , cmpNode : ts . ClassDeclaration , componentDecorator : ts . Node ) {
73
74
const extendNode = cmpNode . heritageClauses && cmpNode . heritageClauses . find ( c => c . token === ts . SyntaxKind . ExtendsKeyword ) ;
74
75
if ( extendNode ) {
75
76
const err = buildError ( diagnostics ) ;
@@ -111,6 +112,23 @@ function validateComponent(config: d.Config, diagnostics: d.Diagnostic[], compon
111
112
augmentDiagnosticWithNode ( config , err , findTagNode ( 'tag' , componentDecorator ) ) ;
112
113
return false ;
113
114
}
115
+
116
+ if ( ! config . _isTesting ) {
117
+ const nonTypeExports = typeChecker . getExportsOfModule ( typeChecker . getSymbolAtLocation ( cmpNode . getSourceFile ( ) ) )
118
+ . filter ( symbol => ( symbol . flags & ( ts . SymbolFlags . Interface | ts . SymbolFlags . TypeAlias ) ) === 0 )
119
+ . filter ( symbol => symbol . name !== cmpNode . name . text ) ;
120
+
121
+ nonTypeExports . forEach ( symbol => {
122
+ const err = buildError ( diagnostics ) ;
123
+ err . messageText = `To allow efficient bundling with rollup, modules using @Component() can only have a single export which is the component class itself.
124
+ Any other exports should be moved to a separate file.
125
+ For further information check out: https://stenciljs.com/docs/module-bundling` ;
126
+ augmentDiagnosticWithNode ( config , err , symbol . valueDeclaration . modifiers [ 0 ] ) ;
127
+ } ) ;
128
+ if ( nonTypeExports . length > 0 ) {
129
+ return false ;
130
+ }
131
+ }
114
132
return true ;
115
133
}
116
134
0 commit comments