Skip to content

Commit

Permalink
fix: stop compilation with some javascript syntax error, close #75 (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzilong authored Apr 1, 2019
1 parent 8c25059 commit 5af247a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ module.exports = function( source, extractComponentsPlugin, loaderContext ) {
]
}

const { metadata } = babel.transform( source, babelOptions )
let metadata

try {
metadata = babel.transform( source, babelOptions ).metadata
} catch ( e ) {
return Promise.reject( e )
}

const components = ( metadata && metadata.megaloComponents ) || {}

Expand Down
2 changes: 1 addition & 1 deletion packages/target/lib/frameworks/vue/loader/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module.exports = function ( source ) {
callback( null, code + `\nexport { render, staticRenderFns }` )
} )
.catch( e => {
loaderContext.emitError( e )
deferred.del()
callback( e, source )
} )
}
Expand Down
11 changes: 10 additions & 1 deletion packages/target/lib/loaders/js-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ module.exports = function ( source ) {
]
}

const { code, map, metadata } = babel.transform( source, babelOptions )
let code, map, metadata

try {
const result = babel.transform( source, babelOptions )
code = result.code
map = result.map
metadata = result.metadata
} catch ( e ) {
callback( e )
}

source = code
sourcemap = map
Expand Down
6 changes: 4 additions & 2 deletions packages/target/lib/platforms/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,13 @@ function genSlotsGeneratorArgs( {

function normalizeGeneratorOptions( options, { constants, extensions } ) {
const entryComponent = options.entryComponent || {}
const root = entryComponent.root || ''
const name = entryComponent.name || ''

// resolve entryComponent src
entryComponent.src = constants.COMPONENT_OUTPUT_PATH
.replace( /\[root\]/g, entryComponent.root ? entryComponent.root + '/' : '' )
.replace( /\[name\]/g, entryComponent.name ) +
.replace( /\[root\]/g, root ? root + '/' : '' )
.replace( /\[name\]/g, name ) +
extensions.template

return options
Expand Down
17 changes: 12 additions & 5 deletions packages/target/lib/plugins/MegaloPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ function modifyResolveOption ( compiler, options ) {
// add to webpack resolve.plugins in order to resolve multi-platform js module
!compiler.options.resolve.plugins && (compiler.options.resolve.plugins = []);
compiler.options.resolve.plugins.push(new MultiPlatformResolver(platform));

// require multi-platform module like a directory
const mainFiles = ['index', `index.${platform}`, 'index.default'];
const extensions = ['.vue', '.js', '.json'];

compiler.options.resolve.mainFiles = getConcatedArray(compiler.options.resolve.mainFiles, mainFiles);
compiler.options.resolve.extensions = getConcatedArray(compiler.options.resolve.extensions, extensions);

Expand Down Expand Up @@ -289,10 +289,17 @@ function normalizePages( { pages, assets, subpackages, entrypoints, platform } )
const newPage = Object.assign( {}, page, { files } )

// subpackage should prefix root
if ( subpackage ) {
page.entryComponent.root = subpackage.root
if ( page.entryComponent ) {
if ( subpackage ) {
page.entryComponent.root = subpackage.root
} else {
page.entryComponent.root = ''
}
} else {
page.entryComponent.root = ''
newPage.entryComponent = {
root: ''
}
// throw new Error( `Cannot parse entry component for "${ page.file }"` )
}

normalized.push( newPage )
Expand Down

0 comments on commit 5af247a

Please sign in to comment.