Merge branch 'master' into tests

pull/4886/head
pushkine 5 years ago
commit deab67bb04

@ -2,6 +2,7 @@
## Unreleased
* Update `<select>` with `bind:value` when the available `<option>`s change ([#1764](https://github.com/sveltejs/svelte/issues/1764))
* Fix inconsistencies when setting a two-way bound `<input>` to `undefined` ([#3569](https://github.com/sveltejs/svelte/issues/3569))
* Fix resize listening on certain older browsers ([#4752](https://github.com/sveltejs/svelte/issues/4752))
* Add `a11y-no-onchange` warning ([#4788](https://github.com/sveltejs/svelte/pull/4788))

@ -77,6 +77,9 @@ npm install && npm run update
npm run dev
```
### Is svelte.dev down?
Probably not, but it's possible. If you can't seem to access any `.dev` sites, check out [this SuperUser question and answer](https://superuser.com/q/1413402).
## License

2337
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -13,14 +13,12 @@
"store",
"animate",
"transition",
"interpolate",
"easing",
"motion",
"svelte",
"README.md"
],
"engines": {
"node": ">= 8"
},
"types": "types/runtime/index.d.ts",
"scripts": {
"test": "mocha",
@ -76,25 +74,25 @@
"@types/puppeteer": "1.3.0",
"@typescript-eslint/eslint-plugin": "^1.13.0",
"@typescript-eslint/parser": "^2.1.0",
"acorn": "^7.1.0",
"agadoo": "^1.1.0",
"c8": "^5.0.1",
"acorn": "^7.2.0",
"agadoo": "^2.0.0",
"c8": "^7.1.2",
"code-red": "0.1.1",
"codecov": "^3.5.0",
"codecov": "^3.6.5",
"css-tree": "1.0.0-alpha22",
"eslint": "^6.3.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-svelte3": "^2.7.3",
"estree-walker": "^1.0.0",
"estree-walker": "^2.0.1",
"is-reference": "^1.1.4",
"jsdom": "^15.1.1",
"jsdom": "^16.2.2",
"kleur": "^3.0.3",
"locate-character": "^2.0.5",
"magic-string": "^0.25.3",
"mocha": "^6.2.0",
"mocha": "^7.1.2",
"periscopic": "^2.0.1",
"puppeteer": "^1.19.0",
"rollup": "^1.27.14",
"puppeteer": "^3.1.0",
"rollup": "^2.10.5",
"source-map": "^0.7.3",
"source-map-support": "^0.5.13",
"tslib": "^1.10.0",

@ -65,7 +65,7 @@ export default [
}),
ts_plugin,
{
writeBundle(bundle) {
writeBundle(_options, bundle) {
if (dir === 'internal') {
const mod = bundle['index.mjs'];
if (mod) {

@ -121,6 +121,9 @@ An element or component can have multiple spread attributes, interspersed with r
<input {...$$restProps}>
```
> The `value` attribute of an `input` element or its children `option` elements must not be set with spread attributes when using `bind:group` or `bind:checked`. Svelte needs to be able to see the element's `value` directly in the markup in these cases so that it can link it to the bound variable.
---
### Text expressions

@ -521,7 +521,7 @@ $: $size = big ? 100 : 10;
### `svelte/transition`
The `svelte/transition` module exports six functions: `fade`, `fly`, `slide`, `scale`, `draw` and `crossfade`. They are for use with Svelte [`transitions`](docs#transition_fn).
The `svelte/transition` module exports seven functions: `fade`, `blur`, `fly`, `slide`, `scale`, `draw` and `crossfade`. They are for use with Svelte [`transitions`](docs#transition_fn).
#### `fade`

@ -1,5 +0,0 @@
---
question: Is svelte.dev down?
---
Probably not, but it's possible. If you can't seem to access any `.dev` sites, check out [this SuperUser question and answer](https://superuser.com/q/1413402).

@ -87,7 +87,7 @@ export default class BindingWrapper {
const update_conditions: any[] = this.needs_lock ? [x`!${lock}`] : [];
const mount_conditions: any[] = [];
const dependency_array = [...this.node.expression.dependencies];
const dependency_array = Array.from(this.get_dependencies());
if (dependency_array.length > 0) {
update_conditions.push(block.renderer.dirty(dependency_array));

@ -13,10 +13,7 @@ function try_require(file) {
}
function normalize_warning(warning) {
warning.frame = warning.frame
.replace(/^\n/, '')
.replace(/^\t+/gm, '')
.replace(/\s+$/gm, '');
warning.frame = warning.frame.replace(/^\n/, '').replace(/^\t+/gm, '').replace(/\s+$/gm, '');
delete warning.filename;
delete warning.toString;
delete warning.start;
@ -29,7 +26,7 @@ function create(code) {
const fn = new Function('module', 'exports', 'require', code);
const module = { exports: {} };
fn(module, module.exports, id => {
fn(module, module.exports, (id) => {
if (id === 'svelte') return require('../../index.js');
if (id.startsWith('svelte/')) return require(id.replace('svelte', '../../'));
@ -61,15 +58,9 @@ describe('css', () => {
const expected_warnings = (config.warnings || []).map(normalize_warning);
const dom = svelte.compile(
input,
Object.assign(config.compileOptions || {}, { format: 'cjs' })
);
const dom = svelte.compile(input, Object.assign(config.compileOptions || {}, { format: 'cjs' }));
const ssr = svelte.compile(
input,
Object.assign(config.compileOptions || {}, { format: 'cjs', generate: 'ssr' })
);
const ssr = svelte.compile(input, Object.assign(config.compileOptions || {}, { format: 'cjs', generate: 'ssr' }));
assert.equal(dom.css.code, ssr.css.code);
@ -82,10 +73,10 @@ describe('css', () => {
writeFileSync(`${__dirname}/samples/${dir}/_actual.css`, dom.css.code);
const expected = {
html: read(`${__dirname}/samples/${dir}/expected.html`),
css: read(`${__dirname}/samples/${dir}/expected.css`)
css: read(`${__dirname}/samples/${dir}/expected.css`),
};
const actual_css = dom.css.code.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz');
const actual_css = dom.css.code.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => ($1 ? m : 'svelte-xyz'));
try {
assert.equal(actual_css, expected.css);
} catch (error) {
@ -140,7 +131,9 @@ describe('css', () => {
// ssr
try {
const actual_ssr = ServerComponent.render(config.props).html.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz');
const actual_ssr = ServerComponent.render(config.props).html.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) =>
$1 ? m : 'svelte-xyz'
);
assert.htmlEqual(actual_ssr, expected.html);
} catch (err) {
console.log(ssr.js.code);

@ -53,7 +53,7 @@ describe('custom-elements', function () {
await browser.close();
});
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach((dir) => {
if (dir[0] === '.') return;
const solo = /\.solo$/.test(dir);
@ -94,9 +94,9 @@ describe('custom-elements', function () {
},
},
virtual({
assert
})
]
assert,
}),
],
});
const result = await bundle.generate({ format: 'iife', name: 'test' });
@ -108,7 +108,7 @@ describe('custom-elements', function () {
console[type](...args);
});
page.on('error', error => {
page.on('error', (error) => {
console.log('>>> an error happened');
console.error(error);
});

@ -47,8 +47,8 @@ export function tryToReadFile(file) {
export function cleanRequireCache() {
Object.keys(require.cache)
.filter(x => x.endsWith('.svelte'))
.forEach(file => delete require.cache[file]);
.filter((x) => x.endsWith('.svelte'))
.forEach((file) => delete require.cache[file]);
}
const virtualConsole = new jsdom.VirtualConsole();
@ -68,7 +68,7 @@ for (const key of Object.getOwnPropertyNames(global)) {
}
// implement mock scroll
window.scrollTo = function(pageXOffset, pageYOffset) {
window.scrollTo = function (pageXOffset, pageYOffset) {
window.pageXOffset = pageXOffset;
window.pageYOffset = pageYOffset;
};
@ -89,11 +89,11 @@ function cleanChildren(node: Element) {
return a.name < b.name ? -1 : 1;
});
attributes.forEach(attr => {
attributes.forEach((attr) => {
node.removeAttribute(attr.name);
});
attributes.forEach(attr => {
attributes.forEach((attr) => {
node.setAttribute(attr.name, attr.value);
});
@ -148,12 +148,8 @@ export function normalizeHtml(window, html) {
export function setupHtmlEqual() {
const window = env();
assert.htmlEqual = (actual, expected, message) => {
assert.deepEqual(
normalizeHtml(window, actual),
normalizeHtml(window, expected),
message
);
assert.htmlEqual = function (actual, expected, message) {
assert.deepEqual(normalizeHtml(window, actual), normalizeHtml(window, expected), message);
};
}
@ -179,24 +175,20 @@ export function addLineNumbers(code) {
.map((line, i) => {
i = String(i + 1);
while (i.length < 3) i = ` ${i}`;
return (
colors.gray(` ${i}: `) +
line.replace(/^\t+/, match => match.split('\t').join(' '))
);
return colors.gray(` ${i}: `) + line.replace(/^\t+/, (match) => match.split('\t').join(' '));
})
.join('\n');
}
export function showOutput(cwd, options = {}, compile = svelte.compile) {
glob('**/*.svelte', { cwd }).forEach(file => {
glob('**/*.svelte', { cwd }).forEach((file) => {
if (file[0] === '_') return;
try {
const { js } = compile(
fs.readFileSync(`${cwd}/${file}`, 'utf-8'),
Object.assign(options, {
filename: file
filename: file,
})
);
@ -226,13 +218,13 @@ export function useFakeTimers() {
return {
flush() {
callbacks.forEach(fn => fn());
callbacks.forEach((fn) => fn());
callbacks.splice(0, callbacks.length);
},
removeFakeTimers() {
callbacks.splice(0, callbacks.length);
global.setTimeout = original_set_timeout;
}
},
};
}

@ -12,13 +12,13 @@ describe('hydration', () => {
before(() => {
const svelte = loadSvelte();
require.extensions['.svelte'] = function(module, filename) {
require.extensions['.svelte'] = function (module, filename) {
const options = Object.assign(
{
filename,
hydratable: true,
format: 'cjs',
sveltePath
sveltePath,
},
compileOptions
);
@ -75,7 +75,7 @@ describe('hydration', () => {
const component = new SvelteComponent({
target,
hydrate: true,
props: config.props
props: config.props,
});
try {
@ -112,18 +112,19 @@ describe('hydration', () => {
}
} catch (err) {
showOutput(cwd, {
hydratable: true
hydratable: true,
});
throw err;
}
if (config.show) showOutput(cwd, {
hydratable: true
});
if (config.show)
showOutput(cwd, {
hydratable: true,
});
});
}
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach((dir) => {
runTest(dir, null);
});
});

@ -23,7 +23,7 @@ describe('motion', () => {
it('sets immediately when duration is 0', () => {
const size = tweened(0);
size.set(100, { duration : 0 });
size.set(100, { duration: 0 });
assert.equal(get(size), 100);
});
});

@ -23,9 +23,12 @@ describe('parser', () => {
const expectedError = tryToLoadJson(`${__dirname}/samples/${dir}/error.json`);
try {
const { ast } = svelte.compile(input, Object.assign(options, {
generate: false
}));
const { ast } = svelte.compile(
input,
Object.assign(options, {
generate: false,
})
);
fs.writeFileSync(`${__dirname}/samples/${dir}/_actual.json`, JSON.stringify(ast, null, '\t'));

@ -0,0 +1,34 @@
export default {
props: {
items: [],
selected: 'two'
},
html: `
<select></select>
<p>selected: two</p>
`,
ssrHtml: `
<select value="two"></select>
<p>selected: two</p>
`,
test({ assert, component, target }) {
component.items = [ 'one', 'two', 'three' ];
const options = target.querySelectorAll('option');
assert.ok(!options[0].selected);
assert.ok(options[1].selected);
assert.ok(!options[2].selected);
assert.htmlEqual(target.innerHTML, `
<select>
<option value='one'>one</option>
<option value='two'>two</option>
<option value='three'>three</option>
</select>
<p>selected: two</p>
`);
}
};

@ -0,0 +1,12 @@
<script>
export let selected;
export let items;
</script>
<select bind:value={selected}>
{#each items as item}
<option>{item}</option>
{/each}
</select>
<p>selected: {selected || 'nothing'}</p>

@ -16,9 +16,9 @@ import { assert } from "../test";
function tryToReadFile(file) {
try {
return fs.readFileSync(file, "utf-8");
return fs.readFileSync(file, 'utf-8');
} catch (err) {
if (err.code !== "ENOENT") throw err;
if (err.code !== 'ENOENT') throw err;
return null;
}
}
@ -26,15 +26,15 @@ function tryToReadFile(file) {
const sveltePath = process.cwd().split("\\").join("/");
let compile = null;
describe("ssr", () => {
describe('ssr', () => {
before(() => {
compile = loadSvelte(true).compile;
return setupHtmlEqual();
});
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === ".") return;
fs.readdirSync(`${__dirname}/samples`).forEach((dir) => {
if (dir[0] === '.') return;
const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`);
@ -45,7 +45,7 @@ describe("ssr", () => {
const show = /\.show/.test(dir);
if (solo && process.env.CI) {
throw new Error("Forgot to remove `solo: true` from test");
throw new Error('Forgot to remove `solo: true` from test');
}
(skip ? it.skip : solo ? it.only : it)(dir, () => {
@ -60,13 +60,13 @@ describe("ssr", () => {
format: "cjs",
};
require("../../register")(compileOptions);
require('../../register')(compileOptions);
try {
const Component = require(`${dir}/main.svelte`).default;
const expectedHtml = tryToReadFile(`${dir}/_expected.html`);
const expectedCss = tryToReadFile(`${dir}/_expected.css`) || "";
const expectedCss = tryToReadFile(`${dir}/_expected.css`) || '';
const props = tryToLoadJson(`${dir}/data.json`) || undefined;
@ -105,10 +105,7 @@ describe("ssr", () => {
fs.writeFileSync(`${dir}/_actual-head.html`, head);
try {
assert.htmlEqual(
head,
fs.readFileSync(`${dir}/_expected-head.html`, 'utf-8')
);
assert.htmlEqual(head, fs.readFileSync(`${dir}/_expected-head.html`, 'utf-8'));
} catch (error) {
if (shouldUpdateExpected()) {
fs.writeFileSync(`${dir}/_expected-head.html`, head);
@ -129,15 +126,15 @@ describe("ssr", () => {
});
// duplicate client-side tests, as far as possible
fs.readdirSync("test/runtime/samples").forEach(dir => {
if (dir[0] === ".") return;
fs.readdirSync('test/runtime/samples').forEach((dir) => {
if (dir[0] === '.') return;
const config = loadConfig(`./runtime/samples/${dir}/_config.js`);
const solo = config.solo || /\.solo/.test(dir);
const skip = config.skip || /\.skip/.test(dir);
if (solo && process.env.CI) {
throw new Error("Forgot to remove `solo: true` from test");
throw new Error('Forgot to remove `solo: true` from test');
}
if (config.skip_if_ssr) return;
@ -156,7 +153,7 @@ describe("ssr", () => {
format: "cjs"
};
require("../../register")(compileOptions);
require('../../register')(compileOptions);
glob("**/*.svelte", { cwd }).forEach((file) => {
if (file[0] === "_") return;
@ -171,13 +168,10 @@ describe("ssr", () => {
mkdirp(dir);
try {
const { js } = compile(
fs.readFileSync(`${cwd}/${file}`, 'utf-8'),
{
...compileOptions,
filename: file
}
);
const { js } = compile(fs.readFileSync(`${cwd}/${file}`, 'utf-8'), {
...compileOptions,
filename: file,
});
fs.writeFileSync(out, js.code);
} catch (err) {
@ -190,7 +184,7 @@ describe("ssr", () => {
const Component = require(`../runtime/samples/${dir}/main.svelte`).default;
const { html } = Component.render(config.props, {
store: (config.store !== true) && config.store
store: config.store !== true && config.store,
});
if (config.ssrHtml) {

Loading…
Cancel
Save