Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include babylon-lightscript with localRequire
- Loading branch information
chee
committed
Dec 19, 2017
1 parent
95bf79f
commit 9a7ff16
Showing
1 changed file
with
14 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
const JSAsset = require('parcel-bundler/src/assets/JSAsset') | ||
const babylon = require('babylon-lightscript') | ||
const localRequire = require('parcel-bundler/src/utils/localRequire') | ||
|
||
module.exports = class LightScriptAsset extends JSAsset { | ||
async parse (code) { | ||
async getParserOptions () { | ||
const options = await super.getParserOptions() | ||
|
||
options.plugins = options.plugins | ||
? options.plugins.concat('lightscript') | ||
? ['lightscript', ...options.plugins] | ||
: ['lightscript'] | ||
|
||
this.contents = babylon.parse(code, options) | ||
return options | ||
} | ||
|
||
async parse (code) { | ||
const babylon = localRequire('babylon-lightscript', this.name) | ||
|
||
const options = await this.getParserOptions() | ||
|
||
this.ast = babylon.parse(code, options) | ||
|
||
return this.contents | ||
return this.ast | ||
} | ||
} |