From e0e434234db527dbce14ef4180f284dd779b6194 Mon Sep 17 00:00:00 2001 From: Irshad PI Date: Mon, 17 Aug 2020 19:22:29 +0530 Subject: [PATCH 1/5] Await: re-throw error when there is no catch block and promise is rejected (#5149) --- .../compile/render_dom/wrappers/AwaitBlock.ts | 1 + src/runtime/internal/await_block.ts | 3 ++ .../samples/await-without-catch/_config.js | 44 +++++++++++++++++++ .../samples/await-without-catch/main.svelte | 9 ++++ 4 files changed, 57 insertions(+) create mode 100644 test/runtime/samples/await-without-catch/_config.js create mode 100644 test/runtime/samples/await-without-catch/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts index 495f1b3157..e890715692 100644 --- a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts @@ -188,6 +188,7 @@ export default class AwaitBlockWrapper extends Wrapper { ctx: #ctx, current: null, token: null, + hasCatch: ${this.catch.node.start !== null ? 'true' : 'false'}, pending: ${this.pending.block.name}, then: ${this.then.block.name}, catch: ${this.catch.block.name}, diff --git a/src/runtime/internal/await_block.ts b/src/runtime/internal/await_block.ts index f70cbd6c2c..3821520837 100644 --- a/src/runtime/internal/await_block.ts +++ b/src/runtime/internal/await_block.ts @@ -59,6 +59,9 @@ export function handle_promise(promise, info) { update(info.then, 1, info.value, value); set_current_component(null); }, error => { + if (!info.hasCatch) { + throw error; + } set_current_component(current_component); update(info.catch, 2, info.error, error); set_current_component(null); diff --git a/test/runtime/samples/await-without-catch/_config.js b/test/runtime/samples/await-without-catch/_config.js new file mode 100644 index 0000000000..2030ed7949 --- /dev/null +++ b/test/runtime/samples/await-without-catch/_config.js @@ -0,0 +1,44 @@ +let fulfil; + +let promise = new Promise(f => { + fulfil = f; +}); + +export default { + props: { + promise + }, + + html: ` +

loading...

+ `, + + test({ assert, component, target }) { + fulfil(42); + + return promise + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

loaded

+ `); + + let reject; + + promise = new Promise((f, r) => { + reject = r; + }); + + component.promise = promise; + + assert.htmlEqual(target.innerHTML, ` +

loading...

+ `); + + reject(new Error('this error should be thrown')); + return promise; + }) + .catch((err) => { + assert.equal(err.message, 'this error should be thrown'); + }); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/await-without-catch/main.svelte b/test/runtime/samples/await-without-catch/main.svelte new file mode 100644 index 0000000000..f528a8bf69 --- /dev/null +++ b/test/runtime/samples/await-without-catch/main.svelte @@ -0,0 +1,9 @@ + + +{#await promise} +

loading...

+{:then value} +

loaded

+{/await} \ No newline at end of file From 1d9e2a13f20e02b3c119d11627fe7b1d811b0167 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 17 Aug 2020 09:53:37 -0400 Subject: [PATCH 2/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceff78b107..e5e886646c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased * Expose object of which slots have received content in `$$slots` ([#2106](https://github.com/sveltejs/svelte/issues/2106)) +* Re-throw an unhandled rejection when an `{#await}` block with no `{:catch}` gets a rejection ([#5129](https://github.com/sveltejs/svelte/issues/5129)) * Add types to `createEventDispatcher` ([#5211](https://github.com/sveltejs/svelte/issues/5211)) * In SSR mode, do not automatically declare variables for reactive assignments to member expressions ([#5247](https://github.com/sveltejs/svelte/issues/5247)) * Include selector in message of `unused-css-selector` warning ([#5252](https://github.com/sveltejs/svelte/issues/5252)) From 82dc26a31c37906153e07686b73d3af08dd50154 Mon Sep 17 00:00:00 2001 From: Antony Jones Date: Thu, 20 Aug 2020 16:51:28 +0100 Subject: [PATCH 3/5] Fix lint warnings (#5263) --- package-lock.json | 4 +- package.json | 2 +- src/compiler/compile/Component.ts | 78 +++++++++---------- src/compiler/compile/index.ts | 4 +- src/compiler/compile/nodes/Binding.ts | 2 +- src/compiler/compile/nodes/Element.ts | 4 +- src/compiler/compile/nodes/Text.ts | 2 +- src/compiler/compile/render_dom/Block.ts | 2 +- src/compiler/compile/render_dom/Renderer.ts | 2 +- .../render_dom/wrappers/Element/Attribute.ts | 10 +-- .../render_dom/wrappers/Element/Binding.ts | 4 +- .../render_dom/wrappers/Element/index.ts | 2 +- .../compile/render_dom/wrappers/IfBlock.ts | 2 +- .../wrappers/InlineComponent/index.ts | 2 +- .../compile/render_dom/wrappers/Window.ts | 4 +- .../wrappers/shared/get_slot_definition.ts | 4 +- .../utils/string_to_member_expression.ts | 4 +- src/compiler/compile/utils/stringify.ts | 2 +- src/compiler/parse/index.ts | 2 +- src/compiler/parse/read/script.ts | 2 +- src/compiler/parse/read/style.ts | 2 +- src/compiler/parse/state/mustache.ts | 16 ++-- src/compiler/parse/state/tag.ts | 20 ++--- src/compiler/parse/state/text.ts | 2 +- src/compiler/parse/utils/entities.ts | 2 +- src/compiler/parse/utils/html.ts | 6 +- src/compiler/preprocess/index.ts | 2 +- src/compiler/utils/fuzzymatch.ts | 4 +- src/compiler/utils/names.ts | 2 +- src/compiler/utils/namespaces.ts | 2 +- src/runtime/store/index.ts | 4 +- .../unused-selector-string-concat/_config.js | 24 +++--- .../unused-selector-ternary-bailed/_config.js | 2 +- .../unused-selector-ternary-concat/_config.js | 10 +-- .../unused-selector-ternary-nested/_config.js | 8 +- test/helpers.js | 1 + .../samples/dynamic-text-nil/_config.js | 4 +- test/hydration/samples/element-ref/_config.js | 2 +- test/js/samples/loop-protect/_config.js | 4 +- test/preprocess/samples/comments/_config.js | 6 +- .../samples/$$rest-without-props/_config.js | 2 +- test/runtime/samples/$$rest/_config.js | 2 +- .../_config.js | 2 +- .../action-ternary-template/_config.js | 4 +- test/runtime/samples/action-this/_config.js | 2 +- .../apply-directives-in-order-2/_config.js | 6 +- .../apply-directives-in-order/_config.js | 2 +- .../attribute-boolean-false/_config.js | 2 +- .../samples/attribute-boolean-true/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../samples/attribute-false/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../runtime/samples/attribute-null/_config.js | 2 +- .../attribute-prefer-expression/_config.js | 4 +- .../samples/attribute-undefined/_config.js | 2 +- .../samples/await-with-update-2/_config.js | 4 +- .../samples/await-with-update/_config.js | 4 +- .../_config.js | 2 +- .../binding-contenteditable-html/_config.js | 4 +- .../_config.js | 2 +- .../binding-contenteditable-text/_config.js | 4 +- .../_config.js | 4 +- .../_config.js | 10 +-- .../_config.js | 2 +- .../binding-input-group-each-1/_config.js | 4 +- .../binding-input-group-each-3/_config.js | 4 +- .../samples/binding-input-number-2/_config.js | 2 +- .../samples/binding-input-number/_config.js | 4 +- .../_config.js | 2 +- .../binding-input-range-change/_config.js | 4 +- .../samples/binding-input-range/_config.js | 4 +- .../_config.js | 4 +- .../_config.js | 2 +- .../binding-input-text-contextual/_config.js | 4 +- .../_config.js | 6 +- .../_config.js | 6 +- .../_config.js | 6 +- .../_config.js | 8 +- .../_config.js | 6 +- .../binding-input-text-deep/_config.js | 6 +- .../binding-input-text-undefined/_config.js | 2 +- .../samples/binding-input-text/_config.js | 4 +- .../binding-select-initial-value/_config.js | 4 +- .../binding-select-optgroup/_config.js | 2 +- .../runtime/samples/binding-select/_config.js | 4 +- .../samples/binding-store-deep/_config.js | 2 +- test/runtime/samples/binding-store/_config.js | 2 +- .../samples/binding-textarea/_config.js | 4 +- .../_config.js | 4 +- .../samples/bitmask-overflow-2/_config.js | 2 +- .../samples/bitmask-overflow-3/_config.js | 2 +- .../bitmask-overflow-slot-2/_config.js | 2 +- .../class-with-spread-and-bind/_config.js | 4 +- .../samples/component-binding-deep/_config.js | 2 +- .../component-binding-store/_config.js | 2 +- .../component-event-not-stale/_config.js | 4 +- .../component-events-console/_config.js | 2 +- .../component-shorthand-import/_config.js | 2 +- .../component-slot-fallback-3/_config.js | 2 +- .../component-slot-fallback-4/_config.js | 2 +- .../component-slot-let-in-slot/_config.js | 2 +- .../component-slot-nested-if/_config.js | 2 +- .../samples/deconflict-builtins-2/_config.js | 2 +- .../dev-warning-missing-data-each/_config.js | 12 +-- .../runtime/samples/document-event/_config.js | 2 +- .../each-block-array-literal/_config.js | 2 +- .../_config.js | 2 +- .../each-block-destructured-array/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 4 +- .../_config.js | 2 +- .../each-block-destructured-object/_config.js | 2 +- .../each-block-else-mount-or-intro/_config.js | 2 +- .../samples/each-block-in-if-block/_config.js | 2 +- .../_config.js | 2 +- .../samples/each-block-keyed-empty/_config.js | 2 +- .../each-block-keyed-non-prop/_config.js | 2 +- .../_config.js | 2 +- .../samples/each-block-keyed-shift/_config.js | 2 +- .../each-block-keyed-siblings/_config.js | 4 +- .../each-block-keyed-static/_config.js | 2 +- .../each-block-scope-shadow-bind-2/_config.js | 2 +- .../each-block-scope-shadow-bind-3/_config.js | 2 +- .../each-block-scope-shadow-bind-4/_config.js | 2 +- .../each-block-scope-shadow-bind/_config.js | 2 +- .../each-block-scope-shadow-self/_config.js | 2 +- .../each-blocks-assignment-2/_config.js | 2 +- .../samples/each-blocks-assignment/_config.js | 2 +- test/runtime/samples/empty-dom/_config.js | 2 +- .../samples/empty-style-block/_config.js | 2 +- .../escape-template-literals/_config.js | 2 +- .../samples/event-handler-async/_config.js | 2 +- .../event-handler-dynamic-2/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../event-handler-dynamic-hash/_config.js | 2 +- .../event-handler-dynamic-invalid/_config.js | 2 +- .../_config.js | 2 +- .../samples/event-handler-dynamic/_config.js | 2 +- .../event-handler-each-this/_config.js | 2 +- .../event-handler-modifier-self/_config.js | 2 +- .../_config.js | 12 +-- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 4 +- .../samples/if-block-else-in-each/_config.js | 4 +- .../if-block-else-partial-outro/_config.js | 4 +- .../_config.js | 2 +- .../_config.js | 2 +- .../samples/initial-state-assign/_config.js | 2 +- .../_config.js | 6 +- .../loop-protect-generator-opt-out/_config.js | 4 +- .../loop-protect-inner-function/_config.js | 2 +- test/runtime/samples/loop-protect/_config.js | 2 +- .../nested-transition-detach-each/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../samples/noscript-removal/_config.js | 2 +- .../paren-wrapped-expressions/_config.js | 2 +- test/runtime/samples/prop-exports/_config.js | 2 +- .../_config.js | 4 +- .../samples/props-reactive-slot/_config.js | 2 +- .../samples/raw-mustache-as-root/_config.js | 2 +- .../raw-mustache-inside-head/_config.js | 2 +- .../raw-mustache-inside-slot/_config.js | 2 +- .../samples/raw-mustaches-td-tr/_config.js | 4 +- .../_config.js | 2 +- .../reactive-import-statement/_config.js | 2 +- .../reactive-value-assign-property/_config.js | 2 +- .../self-reference-component/_config.js | 2 +- .../samples/set-undefined-attr/_config.js | 2 +- .../samples/sigil-component-prop/_config.js | 2 +- .../slot-if-block-update-no-anchor/_config.js | 2 +- .../samples/spread-component-2/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 8 +- .../spread-component-dynamic/_config.js | 8 +- .../_config.js | 2 +- .../samples/spread-each-component/_config.js | 2 +- .../samples/spread-each-element/_config.js | 2 +- .../samples/spread-element-boolean/_config.js | 2 +- .../spread-element-input-value/_config.js | 6 +- .../_config.js | 2 +- .../spread-element-multiple/_config.js | 8 +- .../_config.js | 2 +- .../samples/store-resubscribe-b/_config.js | 2 +- .../store-resubscribe-export/_config.js | 8 +- .../store-resubscribe-observable/_config.js | 2 +- .../svg-tspan-preserve-space/_config.js | 2 +- .../this-in-function-expressions/_config.js | 2 +- .../_config.js | 2 +- .../transition-css-duration/_config.js | 2 +- .../samples/transition-css-iframe/_config.js | 2 +- .../transition-css-in-out-in/_config.js | 2 +- .../_config.js | 2 +- .../transition-js-aborted-outro/_config.js | 4 +- .../transition-js-deferred-b/_config.js | 2 +- .../samples/transition-js-deferred/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../transition-js-local-and-global/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../transition-js-local-nested-if/_config.js | 2 +- .../samples/transition-js-local/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../transition-js-nested-each/_config.js | 2 +- .../transition-js-nested-if/_config.js | 2 +- .../_config.js | 2 +- .../transition-js-parameterised/_config.js | 2 +- .../unchanged-expression-escape/_config.js | 2 +- .../unchanged-expression-xss/_config.js | 2 +- .../samples/whitespace-list/_config.js | 2 +- .../window-bind-scroll-update/_config.js | 2 +- .../window-binding-scroll-store/_config.js | 10 +-- .../samples/window-event-custom/_config.js | 2 +- test/vars/samples/assumed-global/_config.js | 2 +- .../vars/samples/duplicate-globals/_config.js | 2 +- .../duplicate-non-hoistable/_config.js | 2 +- test/vars/samples/duplicate-vars/_config.js | 2 +- .../vars/samples/implicit-reactive/_config.js | 2 +- .../samples/referenced-from-script/_config.js | 32 ++++---- .../samples/template-references/_config.js | 10 +-- test/vars/samples/undeclared/_config.js | 2 +- 235 files changed, 424 insertions(+), 423 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0110595c76..4e9e06824a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -144,8 +144,8 @@ } }, "@sveltejs/eslint-config": { - "version": "github:sveltejs/eslint-config#e8a9b27cd3f7aa66388474412b1a5c11c5a44ade", - "from": "github:sveltejs/eslint-config#v0.0.1", + "version": "github:sveltejs/eslint-config#848ce6464a9ae9c2f3a3095474701dfe9ab851df", + "from": "github:sveltejs/eslint-config#v5.0.0", "dev": true }, "@tootallnate/once": { diff --git a/package.json b/package.json index e0de8670ef..36453769e6 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "@rollup/plugin-sucrase": "^3.0.0", "@rollup/plugin-typescript": "^2.0.1", "@rollup/plugin-virtual": "^2.0.0", - "@sveltejs/eslint-config": "github:sveltejs/eslint-config#v0.0.1", + "@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.0.0", "@types/mocha": "^5.2.7", "@types/node": "^8.10.53", "@typescript-eslint/eslint-plugin": "^3.0.2", diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 88fe197993..ed2b10e404 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -8,7 +8,7 @@ import { create_scopes, extract_names, Scope, - extract_identifiers, + extract_identifiers } from './utils/scope'; import Stylesheet from './css/Stylesheet'; import { test } from '../config'; @@ -155,7 +155,7 @@ export default class Component { ) || { start: 0, end: 0 }; this.warn(svelteOptions, { code: 'custom-element-no-tag', - message: `No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. . To hide this warning, use `, + message: `No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. . To hide this warning, use ` }); } this.tag = this.component_options.tag || compile_options.tag; @@ -190,7 +190,7 @@ export default class Component { this.add_var({ name, injected: true, - referenced: true, + referenced: true }); } else if (name[0] === '$') { this.add_var({ @@ -198,7 +198,7 @@ export default class Component { injected: true, referenced: true, mutated: true, - writable: true, + writable: true }); const subscribable_name = name.slice(1); @@ -289,7 +289,7 @@ export default class Component { } const imported_helpers = Array.from(this.helpers, ([name, alias]) => ({ name, - alias, + alias })); create_module( @@ -305,7 +305,7 @@ export default class Component { .filter(variable => variable.module && variable.export_name) .map(variable => ({ name: variable.name, - as: variable.export_name, + as: variable.export_name })) ); @@ -342,9 +342,9 @@ export default class Component { reassigned: v.reassigned || false, referenced: v.referenced || false, writable: v.writable || false, - referenced_from_script: v.referenced_from_script || false, + referenced_from_script: v.referenced_from_script || false })), - stats: this.stats.render(), + stats: this.stats.render() }; } @@ -409,7 +409,7 @@ export default class Component { source: this.source, start: pos.start, end: pos.end, - filename: this.compile_options.filename, + filename: this.compile_options.filename }); } @@ -441,7 +441,7 @@ export default class Component { pos: pos.start, filename: this.compile_options.filename, toString: () => - `${warning.message} (${start.line}:${start.column})\n${frame}`, + `${warning.message} (${start.line}:${start.column})\n${frame}` }); } @@ -453,7 +453,7 @@ export default class Component { if (node.type === 'ExportDefaultDeclaration') { this.error(node, { code: `default-export`, - message: `A component cannot have a default export`, + message: `A component cannot have a default export` }); } @@ -461,7 +461,7 @@ export default class Component { if (node.source) { this.error(node, { code: `not-implemented`, - message: `A component currently cannot have an export ... from`, + message: `A component currently cannot have an export ... from` }); } if (node.declaration) { @@ -531,10 +531,10 @@ export default class Component { if (node.type === 'LabeledStatement' && node.label.name === '$') { component.warn(node as any, { code: 'module-script-reactive-declaration', - message: '$: has no effect in a module script', + message: '$: has no effect in a module script' }); } - }, + } }); const { scope, globals } = create_scopes(script.content); @@ -544,7 +544,7 @@ export default class Component { if (name[0] === '$') { this.error(node as any, { code: 'illegal-declaration', - message: `The $ prefix is reserved, and cannot be used for variable and import names`, + message: `The $ prefix is reserved, and cannot be used for variable and import names` }); } @@ -562,7 +562,7 @@ export default class Component { if (name[0] === '$') { this.error(node as any, { code: 'illegal-subscription', - message: `Cannot reference store value inside