Skip to content

Commit 2c8268b

Browse files
authoredSep 3, 2017
Merge pull request #812 from sveltejs/gh-781
use component name in runtime dev warnings
2 parents dc48ae6 + 5ca6893 commit 2c8268b

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed
 

‎src/generators/dom/index.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ export default function dom(
147147
.join(',\n')}
148148
}`;
149149

150+
const debugName = `<${generator.customElement ? generator.tag : name}>`;
151+
150152
const constructorBody = deindent`
153+
${options.dev && `this._debugName = '${debugName}';`}
151154
${options.dev && !generator.customElement &&
152155
`if (!options || (!options.target && !options._root)) throw new Error("'target' is a required option");`}
153156
this.options = options;
@@ -160,7 +163,7 @@ export default function dom(
160163
${options.dev &&
161164
Array.from(generator.expectedProperties).map(
162165
prop =>
163-
`if (!('${prop}' in this._state)) console.warn("Component was created without expected data property '${prop}'");`
166+
`if (!('${prop}' in this._state)) console.warn("${debugName} was created without expected data property '${prop}'");`
164167
)}
165168
${generator.bindingGroups.length &&
166169
`this._bindingGroups = [${Array(generator.bindingGroups.length).fill('[]').join(', ')}];`}
@@ -288,13 +291,12 @@ export default function dom(
288291
`);
289292
}
290293

291-
// TODO deprecate component.teardown()
292294
builder.addBlock(deindent`
293295
${options.dev && deindent`
294296
${name}.prototype._checkReadOnly = function _checkReadOnly(newState) {
295297
${Array.from(generator.readonly).map(
296298
prop =>
297-
`if ('${prop}' in newState && !this._updatingReadonlyProperty) throw new Error("Cannot set read-only property '${prop}'");`
299+
`if ('${prop}' in newState && !this._updatingReadonlyProperty) throw new Error("${debugName}: Cannot set read-only property '${prop}'");`
298300
)}
299301
};
300302
`}

‎src/shared/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export function _set(newState) {
151151
export function _setDev(newState) {
152152
if (typeof newState !== 'object') {
153153
throw new Error(
154-
'Component .set was called without an object of data key-values to update.'
154+
this._debugName + ' .set was called without an object of data key-values to update.'
155155
);
156156
}
157157

‎test/runtime/samples/dev-warning-missing-data-binding/_config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export default {
22
dev: true,
33

44
warnings: [
5-
`Component was created without expected data property 'value'`
5+
`<Main$> was created without expected data property 'value'`
66
]
77
};

‎test/runtime/samples/dev-warning-missing-data/_config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default {
22
dev: true,
33

44
warnings: [
5-
`Component was created without expected data property 'foo'`,
6-
`Component was created without expected data property 'bar'`
5+
`<Main$> was created without expected data property 'foo'`,
6+
`<Main$> was created without expected data property 'bar'`
77
]
88
};

‎test/runtime/samples/dev-warning-readonly-computed/_config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
component.set({ foo: 1 });
77
throw new Error( 'Expected an error' );
88
} catch ( err ) {
9-
assert.equal( err.message, `Cannot set read-only property 'foo'` );
9+
assert.equal( err.message, `<Main$>: Cannot set read-only property 'foo'` );
1010
}
1111
}
1212
};

‎test/runtime/samples/dev-warning-readonly-window-binding/_config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
component.set({ width: 99 });
77
throw new Error( 'Expected an error' );
88
} catch ( err ) {
9-
assert.equal( err.message, `Cannot set read-only property 'width'` );
9+
assert.equal( err.message, `<Main$>: Cannot set read-only property 'width'` );
1010
}
1111
}
1212
};

0 commit comments

Comments
 (0)
Please sign in to comment.