Skip to content

Commit

Permalink
Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Mar 5, 2019
1 parent c2a4302 commit d1be7c7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ describe('sourcemaps', function() {
await test(true);
});

it('should create a valid sourcemap when a CSS asset imports SASS', async function() {
it('should create a valid sourcemap when for a CSS asset importing SASS', async function() {
async function test(minify) {
let b = await bundle(
path.join(__dirname, '/integration/sourcemap-sass-imported/style.css'),
Expand Down
14 changes: 1 addition & 13 deletions packages/core/parcel-bundler/src/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Asset {
this.ast = null;
this.generated = null;
this.hash = null;
this.sourceMaps = null;
this.parentDeps = new Set();
this.dependencies = new Map();
this.depAssets = new Map();
Expand Down Expand Up @@ -219,19 +220,6 @@ class Asset {
}

async postProcess(generated) {
let hasMap = false;
let sourceMaps = {};
for (let rendition of generated) {
if (rendition.map && rendition.type == this.type) {
sourceMaps[rendition.type] = rendition.map;
hasMap = true;
}
}

if (hasMap) {
this.sourceMaps = sourceMaps;
}

return generated;
}

Expand Down
13 changes: 13 additions & 0 deletions packages/core/parcel-bundler/src/Pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ class Pipeline {
throw asset.generateErrorMessage(err);
}

let hasMap = false;
let sourceMaps = {};
for (let rendition of generated) {
if (rendition.map && rendition.type == asset.type) {
sourceMaps[rendition.type] = rendition.map;
hasMap = true;
}
}

if (hasMap) {
asset.sourceMaps = sourceMaps;
}

asset.generated = generated;
asset.hash = await asset.generateHash();

Expand Down
2 changes: 0 additions & 2 deletions packages/core/parcel-bundler/src/assets/HTMLAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ class HTMLAsset extends Asset {
}

async postProcess(generated) {
generated = await super.postProcess(generated);

// Replace inline scripts and styles with processed results.
for (let rendition of generated) {
let {type, node} = rendition.meta;
Expand Down
9 changes: 3 additions & 6 deletions packages/core/parcel-bundler/src/assets/JSAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ class JSAsset extends Asset {
}

async generate() {
let enableSourceMaps =
this.options.sourceMaps &&
(!this.rendition || !!this.rendition.sourceMap);
let code;
if (this.isAstDirty) {
let opts = {
Expand All @@ -151,7 +148,7 @@ class JSAsset extends Asset {

let generated = generate(this.ast, opts, this.contents);

if (enableSourceMaps && generated.rawMappings) {
if (this.options.sourceMaps && generated.rawMappings) {
let rawMap = new SourceMap(generated.rawMappings, {
[this.relativeName]: this.contents
});
Expand All @@ -173,7 +170,7 @@ class JSAsset extends Asset {
code = this.outputCode != null ? this.outputCode : this.contents;
}

if (enableSourceMaps && !this.sourceMap) {
if (this.options.sourceMaps && !this.sourceMap) {
this.sourceMap = new SourceMap().generateEmptyMap(
this.relativeName,
this.contents
Expand All @@ -182,7 +179,7 @@ class JSAsset extends Asset {

if (this.globals.size > 0) {
code = Array.from(this.globals.values()).join('\n') + '\n' + code;
if (enableSourceMaps) {
if (this.options.sourceMaps) {
if (!(this.sourceMap instanceof SourceMap)) {
this.sourceMap = await new SourceMap().addMap(this.sourceMap);
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/parcel-bundler/src/assets/VueAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class VueAsset extends Asset {
}

async postProcess(generated) {
generated = await super.postProcess(generated);
let result = [];

let hasScoped = this.ast.styles.some(s => s.scoped);
Expand Down

0 comments on commit d1be7c7

Please sign in to comment.