Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope hoisting for ES6 and CommonJS modules #1135

Merged
merged 188 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
60a91c0
Experimental scope hoisting
devongovett Apr 2, 2018
03f1994
Handle more cases
devongovett Apr 2, 2018
d5f4622
Allow top-level
devongovett Apr 2, 2018
f21dd4c
Bail out of renaming variables when eval is used
devongovett Apr 2, 2018
7c81125
Bundle hoisting fixes
devongovett Apr 3, 2018
cfa1c63
Support code splitting
devongovett Apr 3, 2018
226dfba
Handle more hoisting edge cases
devongovett Apr 3, 2018
89016f5
Dedup added assets
devongovett Apr 3, 2018
fa235a5
Reimplement ES6 modules for scope hoisting
fathyb Apr 4, 2018
96b6ad2
First commonjs support
fathyb Apr 4, 2018
287183a
Add a comment with the filename of each chunk
fathyb Apr 4, 2018
5bb206f
Replace scope instead of declaring vars
fathyb Apr 5, 2018
a468a9d
Use cacheData instead of generate() hack
fathyb Apr 5, 2018
8aee21f
Fix cacheData
fathyb Apr 5, 2018
a55e336
Track whether imports are from ES6
devongovett Apr 5, 2018
a9f10c8
Hoisting improvements
devongovett Apr 5, 2018
f4cef6f
Only write prelude when needed
devongovett Apr 5, 2018
2a9cdb7
Support wildcard exports
fathyb Apr 5, 2018
c295470
Implement export all a different way
devongovett Apr 6, 2018
951ccdc
Create commonjs exports object all at once if possible
devongovett Apr 6, 2018
69576d6
Improve cjs es6 interop
fathyb Apr 7, 2018
7b02682
fix $parcel$require signature
fathyb Apr 7, 2018
5d6f119
rework wildcards
fathyb Apr 7, 2018
a15768c
Rename variable when default exported
devongovett Apr 8, 2018
a4687e5
Handle more types of declarations
devongovett Apr 8, 2018
002c2cf
Handle named re-export extensions
devongovett Apr 8, 2018
b215046
Add test suite for scope hoisting
devongovett Apr 8, 2018
0ab4b18
Resolve namespace imports when possible
devongovett Apr 8, 2018
b908b59
Get correct export names
devongovett Apr 8, 2018
48bb023
Fix wildcards
fathyb Apr 8, 2018
337a06a
Fix es6 wildcard test
fathyb Apr 8, 2018
c384d54
Add export scope test
fathyb Apr 9, 2018
46d8096
Fix export module scope
fathyb Apr 9, 2018
6a6a63a
Add tests for and fix live bindings
devongovett Apr 9, 2018
391d542
Exclude default from wildcard exports
devongovett Apr 9, 2018
a150352
Fix tests
devongovett Apr 9, 2018
9f305c6
Add failing test for export order
devongovett Apr 9, 2018
a2deaf1
More commonjs tests and few bug fixes
devongovett Apr 10, 2018
ea743ae
Add test for dynamic import with scope hoisting
devongovett Apr 10, 2018
c35dbd6
Wrap commonjs modules that non-statically access
devongovett Apr 11, 2018
eab0c86
Support exporting default anonymous declarations
devongovett Apr 11, 2018
a729438
Pass asset id through pipeline
devongovett Apr 11, 2018
7b9f599
Allow `typeof module` to be static
devongovett Apr 11, 2018
bb9a298
Export variables using Declaration.id if present
fathyb Apr 13, 2018
38a0951
Revert to export assignments
fathyb Apr 14, 2018
d150de1
Clean up the code
fathyb Apr 15, 2018
65b1b13
Implement CommonJS wildcard using pure functions
fathyb Apr 15, 2018
9bc914f
typo
fathyb Apr 15, 2018
e6ea095
Use same wildcard helper as babel
fathyb Apr 17, 2018
5a6984a
Fix remaining tests
fathyb Apr 21, 2018
3040363
Fix quotes
fathyb Apr 21, 2018
e147e17
Side effects
fathyb Apr 21, 2018
200a9a7
Try to fix Windows test
fathyb Apr 21, 2018
a4d86db
Try fix windows test again
fathyb Apr 21, 2018
18a0fa8
Only mark top-levels statements as pure
fathyb Apr 22, 2018
bd8d9bd
Revert "Try to fix Windows test"
fathyb Apr 22, 2018
34813b2
Revert sideEffects
fathyb Apr 22, 2018
3dd7758
Fix tests
fathyb Apr 22, 2018
66b4232
Move import/export linking to babel transform instead of string manip…
devongovett Apr 23, 2018
1db6af0
Implement import/require logic in concat
fathyb Apr 23, 2018
a7ce45e
Remove wildcard lookup from packager transform
fathyb Apr 23, 2018
f7978a9
Workaround for CSSAsset
fathyb Apr 24, 2018
1ec53ae
Add uglify without config
fathyb Apr 24, 2018
1564801
Mark default import interop calls as pure
fathyb Apr 24, 2018
c9add7c
Fix binding registration
fathyb Apr 24, 2018
defd105
Revert "Remove wildcard lookup from packager transform"
fathyb Apr 24, 2018
eee8fa4
Implement $parcel$require$resolve in final transform
fathyb Apr 24, 2018
38b7e17
Implement experimental exports remover
fathyb Apr 24, 2018
945f1de
Fix missing await modifiers
fathyb Apr 24, 2018
2ef1f7b
Revert "Revert "Remove wildcard lookup from packager transform""
fathyb Apr 24, 2018
c6bac3c
Revert "Revert "Revert "Remove wildcard lookup from packager transfor…
fathyb Apr 27, 2018
4402c0d
Fix wildcard lookup module resolving
fathyb Apr 27, 2018
0ec5fd8
Make re-export-default test ES6 compliant
fathyb Apr 27, 2018
a3b09a5
Only enable scope hoisting when hmr is disabled
fathyb Apr 28, 2018
8333e89
Prepare code to run all tests
fathyb Apr 28, 2018
6e996e5
Add failling test
fathyb Apr 28, 2018
1b94fe2
Fix bugs and test, improve final bundle size
fathyb Apr 28, 2018
f51883f
Remove commented code
fathyb Apr 28, 2018
c2a27a3
Fix live binding of ES6 imports
fathyb Apr 28, 2018
265d105
Fix and improve default export live bindings
fathyb Apr 28, 2018
7142473
Side effects
fathyb Apr 29, 2018
971a269
Revert "Make re-export-default test ES6 compliant"
fathyb Apr 29, 2018
e8ba820
Fix process and Buffer
fathyb Apr 29, 2018
f6db4bc
Fix Vue.js
fathyb Apr 29, 2018
9f0d0ed
Improve Vue.js support
fathyb Apr 30, 2018
627cfa6
Fix dynamic import
fathyb Apr 30, 2018
f04151c
Implement fast renamer
fathyb Apr 30, 2018
4a89527
Optimizations, improve renaming performance
fathyb Apr 30, 2018
2076f06
Only throw when confident export doesnt exist
fathyb May 1, 2018
5725c49
Wait for packager to write
fathyb May 1, 2018
1e24cb9
Fix browser entry-point resolution
fathyb May 3, 2018
d795034
Merge branch 'master' into fathy/hoist-es6
fathyb May 4, 2018
cb0d4eb
Revert "Fix browser entry-point resolution"
fathyb May 4, 2018
cf1a37f
Merge remote-tracking branch 'origin/master' into fathy/hoist-es6
fathyb May 4, 2018
b1dbe38
Source maps support
fathyb May 4, 2018
9abcf8a
Merge remote-tracking branch 'origin/master' into fathy/hoist-es6
fathyb May 7, 2018
3a4a392
Use asset.getPackage() instead of .package
fathyb May 7, 2018
79e00ed
Simplify stuff a bit
fathyb May 7, 2018
d3844a4
Comment stuff a bit
fathyb May 7, 2018
dfb4d7d
Don't use Babel in transform with scope hoist
fathyb May 8, 2018
97bcd4b
Postprocess assets which generate js
devongovett May 14, 2018
644b145
Run all tests with scope hoisting
devongovett May 14, 2018
b9ae75b
Fix inserting globals with scope hoisting
devongovett May 14, 2018
50af24d
Don't generate a JS source map if coming from a pipeline without one
devongovett May 14, 2018
d743a8c
Fix vue tests with scope hoisting
devongovett May 14, 2018
b9b3523
Remove 'use strict' directives when scope hoisting
devongovett May 14, 2018
6d796b5
Pass glob output through JS asset
devongovett May 14, 2018
9ccaaf3
Fix preloading external bundles with scope hoisting
devongovett May 14, 2018
6978bde
Fix optional requires
devongovett May 14, 2018
6f40a4a
Support UMD exports
devongovett May 14, 2018
09442fd
Don't process prelude + wrapper in concat transform
devongovett May 14, 2018
e9009d9
Remove more unused declarations
devongovett May 14, 2018
f79afac
Apply custom uglify config
devongovett May 14, 2018
9326f81
Restore asset ids from cache
devongovett May 14, 2018
30f7a64
Merge branch 'master' of github.com:parcel-bundler/parcel into fathy/…
devongovett May 14, 2018
bfc6d32
Experiment with using babel-minify instead of uglify
devongovett May 19, 2018
efcd80e
fixes
devongovett May 20, 2018
e412781
Completely remove CommonJS export object in many cases
devongovett May 20, 2018
be908a2
Move mangler to its own file
devongovett May 20, 2018
c3f9203
Move tree shaker to separate file and optimize further
devongovett May 20, 2018
9c7073d
Minify prelude
devongovett May 20, 2018
976d666
Only include UMD output if entry asset actually exports something
devongovett May 20, 2018
129ae33
Fix shaking
devongovett May 20, 2018
13c4fc1
Move renamer into scope hoisting dir
devongovett May 20, 2018
7febf84
clone node before inserting multiple times
devongovett May 20, 2018
eb83005
Remove console
devongovett May 21, 2018
3fb22e2
cleanup
devongovett May 21, 2018
c796181
Fix bundle size reports for scope hoisting
devongovett May 21, 2018
7a76853
Merge branch 'master' of github.com:parcel-bundler/parcel into devon-tmp
devongovett May 22, 2018
cbddeca
fix vue again
devongovett May 22, 2018
7b0ac38
Add __esModule to wrapped ES modules
devongovett May 27, 2018
4bd320f
Refactor scope hoisting
devongovett May 27, 2018
c8b943f
Add test for re-exported ES6 var to commonjs
devongovett May 27, 2018
27b93be
Pass the same cacheData through pipeline
devongovett May 27, 2018
320f886
Support sideEffects: false flag
devongovett May 27, 2018
f6f645b
Clean up
devongovett May 27, 2018
665b23b
Add support for object pattern requires in commonjs
devongovett May 28, 2018
ab08080
Fix requiring external modules
devongovett May 28, 2018
bd27328
cleanup
devongovett May 28, 2018
c3116c3
Merge branch 'master' of github.com:parcel-bundler/parcel into devon-tmp
devongovett May 28, 2018
cd36f00
Fix require template
devongovett May 28, 2018
f3ef4bb
Just use uglify for now
devongovett May 28, 2018
37b36dd
Fix vue
devongovett May 28, 2018
da18575
Fix some tests
devongovett May 28, 2018
596c540
Fix bundle loader order
devongovett May 28, 2018
d2d30d6
Run prettier
devongovett May 28, 2018
c1d3a19
Fix lint
devongovett May 28, 2018
3068d76
rename single binding at a time
devongovett May 29, 2018
9264f12
Merge branch 'master' of github.com:parcel-bundler/parcel into devon-tmp
devongovett May 29, 2018
d98681e
Move all scope hoisting transforms together
devongovett May 29, 2018
b7c7d65
Clean up
devongovett May 29, 2018
d0e3262
Fix elimination of commonjs exports object
devongovett May 29, 2018
bcef25c
Clean up wildcard exports
devongovett May 30, 2018
1fb12e8
Fix object pattern test
devongovett May 30, 2018
7a384a9
Fix bundle loading in old JSPackager
devongovett May 30, 2018
79b498b
Put scope hoisting behind a flag for now
devongovett May 30, 2018
ef6d2a9
Add scopeHoist to cache key
devongovett May 30, 2018
0d0d2a8
Don’t minify in JSAsset generate
devongovett May 30, 2018
542d069
Add CommonJS circular deps test
fathyb May 30, 2018
e8ff5f5
Support assigning to multiple exports in one line
devongovett May 31, 2018
2cae0b4
missing exports should be replaced with an empty object
devongovett May 31, 2018
eae5e24
handle object builtins correctly
devongovett May 31, 2018
c7c0e69
Fix importing a namespace from a commonjs module when code split
devongovett May 31, 2018
1c9167d
Don’t remove assignment if the value is used
devongovett May 31, 2018
b0dbf9c
Attempt to move statements with circular references
devongovett May 31, 2018
532267b
Fix commonjs circular deps
devongovett Jun 1, 2018
1df643f
Wrap module if needed, or move to correct position for side effects
devongovett Jun 5, 2018
6b718bd
Experiment with concatenating ASTs instead of strings
devongovett Jun 10, 2018
e778de8
Correctly handle wrapping of transitive deps
devongovett Jun 10, 2018
3c7bda9
Add tests for tree shaking
devongovett Jun 11, 2018
3474f7a
Dedupe interops
devongovett Jun 11, 2018
4217a65
Handle default interops for code split imports
devongovett Jun 11, 2018
e9c19f5
Correctly support 'import' side effects
devongovett Jun 11, 2018
a2ea1be
Hoist import side effects to the top
devongovett Jun 11, 2018
f797872
Support side effects in re-exports
devongovett Jun 11, 2018
5b9a477
Put default interops in the correct spot
devongovett Jun 11, 2018
f8251b3
Fix requiring modules with undefined exports
devongovett Jun 11, 2018
1a21434
Fix undefined bindings
devongovett Jun 11, 2018
8402841
Improve scope hoisting of wrapped modules
devongovett Jun 13, 2018
0cf74e7
Output module sizes
devongovett Jun 13, 2018
9421d46
Fix wrapped export identifiers
devongovett Jun 13, 2018
65dfdd7
Better unused require result detection
devongovett Jun 13, 2018
9bea36b
Disable source maps for now
devongovett Jun 13, 2018
6ac3356
Fix sideEffects: false
devongovett Jun 13, 2018
21c17b5
Turn off scope hoisting by default
devongovett Jun 13, 2018
cf5ba93
fix lint
devongovett Jun 14, 2018
7a4225a
Merge branch 'master' of github.com:parcel-bundler/parcel into fathy/…
devongovett Jun 14, 2018
dcb8b93
Fix node 6
devongovett Jun 14, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@
"format": "prettier --write \"./{src,bin,test}/**/*.{js,json,md}\"",
"build": "yarn minify && babel src -d lib && ncp src/builtins lib/builtins",
"prepublish": "yarn build",
"minify":
"terser -c -m -o src/builtins/prelude.min.js src/builtins/prelude.js",
"minify": "terser -c -m -o src/builtins/prelude.min.js src/builtins/prelude.js && terser -c -m -o src/builtins/prelude2.min.js src/builtins/prelude2.js",
"precommit": "npm run lint && lint-staged",
"lint":
"eslint . && prettier \"./{src,bin,test}/**/*.{js,json,md}\" --list-different",
Expand Down
33 changes: 23 additions & 10 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Bundler extends EventEmitter {

this.resolver = new Resolver(this.options);
this.parser = new Parser(this.options);
this.packagers = new PackagerRegistry();
this.packagers = new PackagerRegistry(this.options);
this.cache = this.options.cache ? new FSCache(this.options) : null;
this.delegate = options.delegate || {};
this.bundleLoaders = {};
Expand Down Expand Up @@ -91,6 +91,14 @@ class Bundler extends EventEmitter {
const watch =
typeof options.watch === 'boolean' ? options.watch : !isProduction;
const target = options.target || 'browser';
const hmr =
target === 'node'
? false
: typeof options.hmr === 'boolean'
? options.hmr
: watch;
const scopeHoist =
options.scopeHoist !== undefined ? options.scopeHoist : false;
return {
production: isProduction,
outDir: Path.resolve(options.outDir || 'dist'),
Expand All @@ -104,19 +112,15 @@ class Bundler extends EventEmitter {
minify:
typeof options.minify === 'boolean' ? options.minify : isProduction,
target: target,
hmr:
target === 'node'
? false
: typeof options.hmr === 'boolean'
? options.hmr
: watch,
hmr: hmr,
https: options.https || false,
logLevel: isNaN(options.logLevel) ? 3 : options.logLevel,
entryFiles: this.entryFiles,
hmrPort: options.hmrPort || 0,
rootDir: getRootDir(this.entryFiles),
sourceMaps:
typeof options.sourceMaps === 'boolean' ? options.sourceMaps : true,
(typeof options.sourceMaps === 'boolean' ? options.sourceMaps : true) &&
!scopeHoist,
hmrHostname:
options.hmrHostname ||
(options.target === 'electron' ? 'localhost' : ''),
Expand All @@ -126,6 +130,7 @@ class Bundler extends EventEmitter {
typeof options.autoinstall === 'boolean'
? options.autoinstall
: !isProduction,
scopeHoist: scopeHoist,
contentHash:
typeof options.contentHash === 'boolean'
? options.contentHash
Expand Down Expand Up @@ -246,6 +251,8 @@ class Bundler extends EventEmitter {
asset.invalidateBundle();
}

logger.status(emoji.progress, `Producing bundles...`);

// Create a root bundle to hold all of the entry assets, and add them to the tree.
this.mainBundle = new Bundle();
for (let asset of this.entryAssets) {
Expand All @@ -271,6 +278,8 @@ class Bundler extends EventEmitter {
this.hmr.emitUpdate(changedAssets);
}

logger.status(emoji.progress, `Packaging...`);

// Package everything up
this.bundleHashes = await this.mainBundle.package(
this,
Expand Down Expand Up @@ -318,7 +327,7 @@ class Bundler extends EventEmitter {
}

await this.loadPlugins();

if (!this.options.env) {
await loadEnv(Path.join(this.options.rootDir, 'index'));
this.options.env = process.env;
Expand Down Expand Up @@ -508,14 +517,17 @@ class Bundler extends EventEmitter {
let processed = this.cache && (await this.cache.read(asset.name));
let cacheMiss = false;
if (!processed || asset.shouldInvalidate(processed.cacheData)) {
processed = await this.farm.run(asset.name);
processed = await this.farm.run(asset.name, asset.id);
processed.id = asset.id;
cacheMiss = true;
}

asset.endTime = Date.now();
asset.buildTime = asset.endTime - asset.startTime;
asset.id = processed.id;
asset.generated = processed.generated;
asset.hash = processed.hash;
asset.cacheData = processed.cacheData;

// Call the delegate to get implicit dependencies
let dependencies = processed.dependencies;
Expand All @@ -535,6 +547,7 @@ class Bundler extends EventEmitter {
// that changing it triggers a recompile of the parent.
this.watch(dep.name, asset);
} else {
dep.parent = asset.name;
let assetDep = await this.resolveDep(asset, dep);
if (assetDep) {
await this.loadAsset(assetDep);
Expand Down
2 changes: 1 addition & 1 deletion src/FSCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const pkg = require('../package.json');
const logger = require('./Logger');

// These keys can affect the output, so if they differ, the cache should not match
const OPTION_KEYS = ['publicURL', 'minify', 'hmr', 'target'];
const OPTION_KEYS = ['publicURL', 'minify', 'hmr', 'target', 'scopeHoist'];

class FSCache {
constructor(options) {
Expand Down
4 changes: 2 additions & 2 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class Parser {
this.extensions[ext.toLowerCase()] = parser;
}

findParser(filename) {
if (/[*+{}]/.test(filename) && glob.hasMagic(filename)) {
findParser(filename, fromPipeline) {
if (!fromPipeline && /[*+{}]/.test(filename) && glob.hasMagic(filename)) {
return GlobAsset;
}

Expand Down
15 changes: 10 additions & 5 deletions src/Pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ class Pipeline {
this.parser = new Parser(options);
}

async process(path, isWarmUp) {
async process(path, id, isWarmUp) {
let options = this.options;
if (isWarmUp) {
options = Object.assign({isWarmUp}, options);
}

let asset = this.parser.getAsset(path, options);
asset.id = id;

let generated = await this.processAsset(asset);
let generatedMap = {};
for (let rendition of generated) {
Expand Down Expand Up @@ -52,17 +54,19 @@ class Pipeline {
// Find an asset type for the rendition type.
// If the asset is not already an instance of this asset type, process it.
let AssetType = this.parser.findParser(
asset.name.slice(0, -inputType.length) + type
asset.name.slice(0, -inputType.length) + type,
true
);
if (!(asset instanceof AssetType)) {
let opts = Object.assign({rendition}, asset.options);
let opts = Object.assign({}, asset.options, {rendition});
let subAsset = new AssetType(asset.name, opts);
subAsset.id = asset.id;
subAsset.contents = value;
subAsset.dependencies = asset.dependencies;
subAsset.cacheData = Object.assign(asset.cacheData, subAsset.cacheData);

let processed = await this.processAsset(subAsset);
generated = generated.concat(processed);
Object.assign(asset.cacheData, subAsset.cacheData);
asset.hash = md5(asset.hash + subAsset.hash);
} else {
generated.push(rendition);
Expand Down Expand Up @@ -98,7 +102,8 @@ class Pipeline {
yield {
type,
value: asset.generated[type],
final: true
// for scope hoisting, we need to post process all JS
final: !(type === 'js' && this.options.scopeHoist)
};
}
}
Expand Down
79 changes: 68 additions & 11 deletions src/SourceMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class SourceMap {
column: mapping.original.column
});

if (!originalMapping.line) {
return false;
if (!originalMapping || !originalMapping.line) {
return;
}

this.addMapping({
Expand Down Expand Up @@ -182,7 +182,60 @@ class SourceMap {
return this;
}

findClosest(line, column, key = 'original') {
findClosestGenerated(line, column) {
if (line < 1) {
throw new Error('Line numbers must be >= 1');
}

if (column < 0) {
throw new Error('Column numbers must be >= 0');
}

if (this.mappings.length < 1) {
return undefined;
}

let startIndex = 0;
let stopIndex = this.mappings.length - 1;
let middleIndex = (stopIndex + startIndex) >>> 1;

while (
startIndex < stopIndex &&
this.mappings[middleIndex].generated.line !== line
) {
let mid = this.mappings[middleIndex].generated.line;
if (line < mid) {
stopIndex = middleIndex - 1;
} else if (line > mid) {
startIndex = middleIndex + 1;
}
middleIndex = (stopIndex + startIndex) >>> 1;
}

let mapping = this.mappings[middleIndex];
if (!mapping || mapping.generated.line !== line) {
return this.mappings.length - 1;
}

while (
middleIndex >= 1 &&
this.mappings[middleIndex - 1].generated.line === line
) {
middleIndex--;
}

while (
middleIndex < this.mappings.length - 1 &&
this.mappings[middleIndex + 1].generated.line === line &&
column > this.mappings[middleIndex].generated.column
) {
middleIndex++;
}

return middleIndex;
}

findClosest(line, column, key) {
if (line < 1) {
throw new Error('Line numbers must be >= 1');
}
Expand Down Expand Up @@ -211,7 +264,7 @@ class SourceMap {
middleIndex = Math.floor((stopIndex + startIndex) / 2);
}

let mapping = this.mappings[middleIndex];
var mapping = this.mappings[middleIndex];
if (!mapping || mapping[key].line !== line) {
return this.mappings.length - 1;
}
Expand All @@ -235,16 +288,20 @@ class SourceMap {
}

originalPositionFor(generatedPosition) {
let index = this.findClosest(
let index = this.findClosestGenerated(
generatedPosition.line,
generatedPosition.column,
'generated'
generatedPosition.column
);
let mapping = this.mappings[index];
if (!mapping) {
return null;
}

return {
source: this.mappings[index].source,
name: this.mappings[index].name,
line: this.mappings[index].original.line,
column: this.mappings[index].original.column
source: mapping.source,
name: mapping.name,
line: mapping.original.line,
column: mapping.original.column
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/assets/CSSAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CSSAsset extends Asset {
{
type: 'js',
value: js,
final: true
hasDependencies: false
}
];
}
Expand Down
4 changes: 1 addition & 3 deletions src/assets/GLSLAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ class GLSLAsset extends Asset {
const glslifyBundle = await localRequire('glslify-bundle', this.name);
let glsl = glslifyBundle(this.ast);

return {
js: `module.exports=${JSON.stringify(glsl)};`
};
return `module.exports=${JSON.stringify(glsl)};`;
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/assets/GlobAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ class GlobAsset extends Asset {
}

generate() {
return {
js: 'module.exports = ' + generate(this.contents) + ';'
};
return [
{
type: 'js',
value: 'module.exports = ' + generate(this.contents) + ';'
}
];
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/assets/GraphqlAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class GraphqlAsset extends Asset {
}

generate() {
return {
js: `module.exports=${JSON.stringify(this.ast, false, 2)};`
};
return `module.exports=${JSON.stringify(this.ast, false, 2)};`;
}
}

Expand Down
Loading