diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index c6b1f1b9a86b..a84f8fefa6cd 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -146,9 +146,18 @@ export default function dom( const hasInitHooks = !!(templateProperties.oncreate || templateProperties.onstate || templateProperties.onupdate); const constructorBody = deindent` - ${options.dev && `this._debugName = '${debugName}';`} - ${options.dev && !component.customElement && - `if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");`} + ${options.dev && deindent` + this._debugName = '${debugName}'; + ${!component.customElement && deindent` + if (!options || (!options.target && !options.root)) { + throw new Error("'target' is a required option"); + }`} + ${storeProps.length > 0 && deindent` + if (!options.store) { + throw new Error("${debugName} references store properties, but no store was provided"); + }`} + `} + @init(this, options); ${templateProperties.store && `this.store = %store();`} ${component.refs.size > 0 && `this.refs = {};`} diff --git a/src/compile/render-ssr/index.ts b/src/compile/render-ssr/index.ts index f53d35fdb1e2..a424b5c2ea02 100644 --- a/src/compile/render-ssr/index.ts +++ b/src/compile/render-ssr/index.ts @@ -75,6 +75,8 @@ export default function ssr( ); } + const debugName = `<${component.customElement ? component.tag : name}>`; + // TODO concatenate CSS maps const result = (deindent` ${js} @@ -113,6 +115,12 @@ export default function ssr( ${templateProperties.store && `options.store = %store();`} __result.addComponent(${name}); + ${options.dev && storeProps.length > 0 && deindent` + if (!options.store) { + throw new Error("${debugName} references store properties, but no store was provided"); + } + `} + ctx = Object.assign(${initialState.join(', ')}); ${computations.map( diff --git a/test/cli/samples/dev/expected/Main.js b/test/cli/samples/dev/expected/Main.js index 37f062e3976c..be11885fa0d1 100644 --- a/test/cli/samples/dev/expected/Main.js +++ b/test/cli/samples/dev/expected/Main.js @@ -28,7 +28,10 @@ function create_main_fragment(component, ctx) { function Main(options) { this._debugName = '
'; - if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option"); + if (!options || (!options.target && !options.root)) { + throw new Error("'target' is a required option"); + } + init(this, options); this._state = assign({}, options.data); this._intro = true; diff --git a/test/runtime/index.js b/test/runtime/index.js index 7e16f4d17981..c16d5164dd37 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -69,7 +69,6 @@ describe("runtime", () => { compileOptions = config.compileOptions || {}; compileOptions.shared = shared; compileOptions.hydratable = hydrate; - compileOptions.dev = config.dev; compileOptions.store = !!config.store; compileOptions.immutable = config.immutable; compileOptions.skipIntroByDefault = config.skipIntroByDefault; @@ -171,7 +170,11 @@ describe("runtime", () => { }) .catch(err => { if (config.error && !unintendedError) { - config.error(assert, err); + if (typeof config.error === 'function') { + config.error(assert, err); + } else { + assert.equal(config.error, err.message); + } } else { failed.add(dir); showOutput(cwd, { diff --git a/test/runtime/samples/binding-indirect-computed/_config.js b/test/runtime/samples/binding-indirect-computed/_config.js index 595c5f3a9596..020a9f3afa5a 100644 --- a/test/runtime/samples/binding-indirect-computed/_config.js +++ b/test/runtime/samples/binding-indirect-computed/_config.js @@ -1,5 +1,7 @@ export default { - dev: true, + compileOptions: { + dev: true + }, html: `