Skip to content

Commit

Permalink
Merge branch 'v2' into improve-elm-compiler-error-output
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed May 17, 2022
2 parents 177f76b + 8981c88 commit 9f350a2
Show file tree
Hide file tree
Showing 33 changed files with 792 additions and 637 deletions.
411 changes: 199 additions & 212 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/core/cache/package.json
Expand Up @@ -27,7 +27,7 @@
"@parcel/fs": "2.5.0",
"@parcel/logger": "2.5.0",
"@parcel/utils": "2.5.0",
"lmdb": "2.3.7"
"lmdb": "2.3.10"
},
"peerDependencies": {
"@parcel/core": "^2.5.0"
Expand Down
3 changes: 3 additions & 0 deletions packages/core/core/src/ParcelConfig.schema.js
Expand Up @@ -93,6 +93,9 @@ const mapStringSchema = (pluginType: string, key: string): SchemaEntity => {
export default {
type: 'object',
properties: {
$schema: {
type: 'string',
},
extends: {
oneOf: [
{
Expand Down
6 changes: 3 additions & 3 deletions packages/core/integration-tests/test/cache.js
Expand Up @@ -4901,17 +4901,17 @@ describe('cache', function () {
},
async update(b) {
let res = await run(b.bundleGraph);
assert(res.includes("let a = 'a'"));
assert(res.includes(`let a = "a"`));

await overlayFS.writeFile(
path.join(inputDir, 'src/entries/a.js'),
"export let a = 'b';",
`export let a = "b";`,
);
},
});

let res = await run(b.bundleGraph);
assert(res.includes("let a = 'b'"));
assert(res.includes(`let a = "b"`));
});

it('should invalidate when switching to a different packager for an inline bundle', async function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/fs.js
Expand Up @@ -198,7 +198,7 @@ describe('fs', function () {
path.join(distDir, 'index.js'),
'utf8',
);
assert(contents.includes("require('fs')"));
assert(contents.includes(`require("fs")`));
assert(contents.includes('readFileSync'));

await outputFS.writeFile(
Expand Down
4 changes: 2 additions & 2 deletions packages/core/integration-tests/test/html.js
Expand Up @@ -2549,7 +2549,7 @@ describe('html', function () {
await getNextBuild(b);

let html = await outputFS.readFile('/dist/index.html', 'utf8');
assert(html.includes("console.log('test')"));
assert(html.includes(`console.log("test")`));

await overlayFS.writeFile(
path.join(__dirname, '/html-inline-js-require/test.js'),
Expand All @@ -2558,7 +2558,7 @@ describe('html', function () {
await getNextBuild(b);

html = await outputFS.readFile(path.join(distDir, '/index.html'), 'utf8');
assert(html.includes("console.log('foo')"));
assert(html.includes(`console.log("foo")`));
});

it('should invalidate parent bundle when nested inline bundles change', async function () {
Expand Down
@@ -0,0 +1,17 @@
import returnThisDefault, { returnThis } from "./other.js";
import * as other from "./other.js";

import returnThisWrappedDefault, { returnThis as returnThisWrapped } from "./other-wrapped.js";
import * as otherWrapped from "./other-wrapped.js";

let result = {
unwrappedNamed: returnThis(),
unwrappedDefault: returnThisDefault(),
unwrappedNamespace: other.returnThis(),
wrappedNamed: returnThisWrapped(),
wrappedDefault: returnThisWrappedDefault(),
wrappedNamespace: otherWrapped.returnThis(),
};

output = result;
export default result;
@@ -0,0 +1,13 @@
import * as ns from "./other-wrapped.js";

let y = typeof module !== "undefined" ? module : {};

export function returnThis() {
if (y != null) {
return [this === undefined, this === ns];
} else {
throw new Error();
}
}

export default returnThis;
@@ -0,0 +1,7 @@
import * as ns from "./other.js";

export function returnThis() {
return [this === undefined, this === ns];
}

export default returnThis;
@@ -0,0 +1,4 @@
import {B} from './b.js';
import {C} from './c.js';

output = [new B()[Symbol.toStringTag], new C()[Symbol.toStringTag]];
@@ -0,0 +1,5 @@
export class B {
get [Symbol.toStringTag]() {
return '1';
}
}
@@ -0,0 +1,5 @@
export class C {
get [Symbol.toStringTag]() {
return '2';
}
}
@@ -0,0 +1,3 @@
{
"browserslist": "Chrome 50"
}
Expand Up @@ -4,6 +4,6 @@ console.log('bar');
/* block comment line */
console.log('baz');
/* multi line
block comment
block comment
*/
console.log('idhf');
33 changes: 24 additions & 9 deletions packages/core/integration-tests/test/javascript.js
Expand Up @@ -1084,8 +1084,8 @@ describe('javascript', function () {
let main = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
dedicated = await outputFS.readFile(dedicated.filePath, 'utf8');
shared = await outputFS.readFile(shared.filePath, 'utf8');
assert(/new Worker(.*?, {[\n\s]+type: 'module'[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+type: 'module'[\n\s]+})/.test(main));
assert(/new Worker(.*?, {[\n\s]+type: "module"[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+type: "module"[\n\s]+})/.test(main));
});

for (let shouldScopeHoist of [true, false]) {
Expand Down Expand Up @@ -1238,8 +1238,8 @@ describe('javascript', function () {
);

let main = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(/new Worker(.*?, {[\n\s]+name: 'worker'[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+name: 'shared'[\n\s]+})/.test(main));
assert(/new Worker(.*?, {[\n\s]+name: "worker"[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+name: "shared"[\n\s]+})/.test(main));
});

it('should error if importing in a worker without type: module', async function () {
Expand Down Expand Up @@ -1438,7 +1438,7 @@ describe('javascript', function () {
]);

let res = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(res.includes("importScripts('imported.js')"));
assert(res.includes(`importScripts("imported.js")`));
});

it('should ignore importScripts in script workers when not passed a string literal', async function () {
Expand Down Expand Up @@ -1484,7 +1484,7 @@ describe('javascript', function () {
]);

let res = await outputFS.readFile(b.getBundles()[1].filePath, 'utf8');
assert(res.includes("importScripts('https://unpkg.com/parcel')"));
assert(res.includes(`importScripts("https://unpkg.com/parcel")`));
});

it('should support bundling service-workers', async function () {
Expand Down Expand Up @@ -1559,7 +1559,7 @@ describe('javascript', function () {
let main = bundles.find(b => !b.env.isWorker());
let mainContents = await outputFS.readFile(main.filePath, 'utf8');
assert(
/navigator.serviceWorker.register\(.*?, {[\n\s]*scope: 'foo'[\n\s]*}\)/.test(
/navigator.serviceWorker.register\(.*?, {[\n\s]*scope: "foo"[\n\s]*}\)/.test(
mainContents,
),
);
Expand Down Expand Up @@ -4384,7 +4384,7 @@ describe('javascript', function () {
let res = await run(b);
assert.equal(
res.default,
"<p>test</p>\n<script>console.log('hi');\n\n</script>\n",
`<p>test</p>\n<script>console.log("hi");\n\n</script>\n`,
);
});

Expand Down Expand Up @@ -5267,6 +5267,21 @@ describe('javascript', function () {
assert.deepEqual(res.default, 'x: 123');
});

it('should call named imports without this context', async function () {
let b = await bundle(
path.join(__dirname, 'integration/js-import-this/index.js'),
);
let res = await run(b, {output: null}, {strict: true});
assert.deepEqual(res.default, {
unwrappedNamed: [true, false],
unwrappedDefault: [true, false],
unwrappedNamespace: [false, true],
wrappedNamed: [true, false],
wrappedDefault: [true, false],
wrappedNamespace: [false, true],
});
});

it('should only replace free references to require', async () => {
let b = await bundle(
path.join(__dirname, 'integration/js-require-free/index.js'),
Expand Down Expand Up @@ -5541,7 +5556,7 @@ describe('javascript', function () {
},
end: {
line: 1,
column: 0,
column: 1,
},
},
],
Expand Down
6 changes: 3 additions & 3 deletions packages/core/integration-tests/test/output-formats.js
Expand Up @@ -191,7 +191,7 @@ describe('output formats', function () {

let dist = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(dist.includes('= require("lodash")'));
assert(dist.includes('= ($parcel$interopDefault('));
assert(dist.includes('= (0, ($parcel$interopDefault('));
assert(/var {add: \s*\$.+?\$add\s*} = lodash/);
assert.equal((await run(b)).bar, 6);
});
Expand Down Expand Up @@ -987,7 +987,7 @@ describe('output formats', function () {
assert.equal(await res.output, 4);
});

it('should support use an import polyfill for older browsers', async function () {
it('should support using an import polyfill for older browsers', async function () {
let b = await bundle(
path.join(__dirname, '/integration/formats/esm-browser/index.html'),
{
Expand Down Expand Up @@ -1024,7 +1024,7 @@ describe('output formats', function () {
.find(bundle => bundle.name.startsWith('async'));
assert(
new RegExp(
"getBundleURL\\('[a-zA-Z0-9]+'\\) \\+ \"" +
`getBundleURL\\("[a-zA-Z0-9]+"\\) \\+ "` +
path.basename(asyncBundle.filePath) +
'"',
).test(entry),
Expand Down
34 changes: 34 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Expand Up @@ -169,6 +169,23 @@ describe('scope hoisting', function () {
assert.equal(output, 2);
});

it('supports renaming helpers inserted during transpiling', async function () {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/rename-helpers/a.js',
),
);
let contents = await outputFS.readFile(
b.getBundles()[0].filePath,
'utf8',
);
assert(/let \S* = Symbol.toStringTag;/.test(contents));

let output = await run(b);
assert.deepEqual(output, ['1', '2']);
});

it('supports renaming imports', async function () {
let b = await bundle(
path.join(
Expand Down Expand Up @@ -5284,6 +5301,23 @@ describe('scope hoisting', function () {
assert.deepEqual(res, 'x: 123');
});

it('should call named imports without this context', async function () {
let b = await bundle(
path.join(__dirname, 'integration/js-import-this/index.js'),
);
let res = await run(b, {output: null}, {strict: true});
assert.deepEqual(res, {
unwrappedNamed: [true, false],
unwrappedDefault: [true, false],
// TODO: unwrappedNamespace should actually be `[false, true]` but we optimize
// the `ns.foo` expression into a named import, so that namespace isn't available anymore.
unwrappedNamespace: [true, false],
wrappedNamed: [true, false],
wrappedDefault: [true, false],
wrappedNamespace: [false, true],
});
});

it('should insert the prelude for sibling bundles referenced in HTML', async function () {
let b = await bundle(
path.join(
Expand Down

0 comments on commit 9f350a2

Please sign in to comment.