Skip to content

Commit 75651bb

Browse files
committed
use component name in runtime dev warnings - fixes #781
1 parent 0e80248 commit 75651bb

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)
@@ -290,13 +293,12 @@ export default function dom(
290293
`);
291294
}
292295

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

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)