Merge pull request from sveltejs/component-name-conflict

Prevent component name conflict
pull/2026/head
Rich Harris 6 years ago committed by GitHub
commit bcd45c79df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
{ {
"name": "svelte", "name": "svelte",
"version": "3.0.0-alpha20", "version": "3.0.0-alpha21",
"description": "The magical disappearing UI framework", "description": "The magical disappearing UI framework",
"module": "index.mjs", "module": "index.mjs",
"main": "index.js", "main": "index.js",

@ -93,7 +93,7 @@ export default class Component {
options: CompileOptions, options: CompileOptions,
stats: Stats stats: Stats
) { ) {
this.name = this.getUniqueName(name); this.name = name;
this.stats = stats; this.stats = stats;
this.ast = ast; this.ast = ast;
@ -131,6 +131,7 @@ export default class Component {
this.walk_module_js(); this.walk_module_js();
this.walk_instance_js_pre_template(); this.walk_instance_js_pre_template();
this.name = this.getUniqueName(name);
this.fragment = new Fragment(this, ast.html); this.fragment = new Fragment(this, ast.html);
this.walk_instance_js_post_template(); this.walk_instance_js_post_template();

@ -34,7 +34,7 @@ describe("runtime", () => {
require.extensions[".html"] = function(module, filename) { require.extensions[".html"] = function(module, filename) {
const options = Object.assign( const options = Object.assign(
{ filename, name: getName(filename), format: 'cjs', sveltePath }, { filename, name: compileOptions.name || getName(filename), format: 'cjs', sveltePath },
compileOptions compileOptions
); );

@ -0,0 +1,9 @@
export default {
compileOptions: {
name: 'Set'
},
preserveIdentifiers: true,
html: `<p>true</p>`
};

@ -0,0 +1,5 @@
<script>
let set = new Set(['x']);
</script>
<p>{set.has('x')}</p>

@ -4,6 +4,6 @@ export default {
}, },
warnings: [ warnings: [
`<Main$> was created without expected prop 'value'` `<Main> was created without expected prop 'value'`
] ]
}; };

@ -4,6 +4,6 @@ export default {
}, },
warnings: [ warnings: [
`<Foo$> was created without expected prop 'y'` `<Foo> was created without expected prop 'y'`
] ]
}; };

@ -4,7 +4,7 @@ export default {
}, },
warnings: [ warnings: [
`<Main$> was created without expected prop 'foo'`, `<Main> was created without expected prop 'foo'`,
`<Main$> was created without expected prop 'bar'` `<Main> was created without expected prop 'bar'`
] ]
}; };

@ -12,7 +12,7 @@ export default {
component.foo = 1; component.foo = 1;
throw new Error( 'Expected an error' ); throw new Error( 'Expected an error' );
} catch ( err ) { } catch ( err ) {
assert.equal( err.message, `<Main$>: Cannot set read-only property 'foo'` ); assert.equal( err.message, `<Main>: Cannot set read-only property 'foo'` );
} }
} }
}; };

@ -8,7 +8,7 @@ export default {
component.width = 99; component.width = 99;
throw new Error('Expected an error'); throw new Error('Expected an error');
} catch (err) { } catch (err) {
assert.equal(err.message, `<Main$>: Cannot set read-only property 'width'`); assert.equal(err.message, `<Main>: Cannot set read-only property 'width'`);
} }
} }
}; };
Loading…
Cancel
Save