@@ -5,15 +5,15 @@ import { DEFAULT_STYLE_MODE, augmentDiagnosticWithNode, buildError, validateComp
55import { CLASS_DECORATORS_TO_REMOVE } from '../remove-stencil-import' ;
66
77
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 ) {
99 removeDecorators ( cmpNode , CLASS_DECORATORS_TO_REMOVE ) ;
1010
1111 const [ componentOptions ] = getDeclarationParameters < d . ComponentOptions > ( componentDecorator ) ;
1212 if ( ! componentOptions ) {
1313 return ;
1414 }
1515
16- if ( ! validateComponent ( config , diagnostics , componentOptions , cmpNode , componentDecorator ) ) {
16+ if ( ! validateComponent ( config , diagnostics , typeChecker , componentOptions , cmpNode , componentDecorator ) ) {
1717 return ;
1818 }
1919
@@ -67,9 +67,10 @@ export function componentDecoratorToStatic(config: d.Config, diagnostics: d.Diag
6767 newMembers . push ( createStaticGetter ( 'styles' , convertValueToLiteral ( styles ) ) ) ;
6868 }
6969 }
70+
7071}
7172
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 ) {
7374 const extendNode = cmpNode . heritageClauses && cmpNode . heritageClauses . find ( c => c . token === ts . SyntaxKind . ExtendsKeyword ) ;
7475 if ( extendNode ) {
7576 const err = buildError ( diagnostics ) ;
@@ -111,6 +112,23 @@ function validateComponent(config: d.Config, diagnostics: d.Diagnostic[], compon
111112 augmentDiagnosticWithNode ( config , err , findTagNode ( 'tag' , componentDecorator ) ) ;
112113 return false ;
113114 }
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+ }
114132 return true ;
115133}
116134
0 commit comments