Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components should be able to explicitly specify 'undefined' as default prop value #2635

Closed
Conduitry opened this issue May 1, 2019 · 1 comment · Fixed by #2637
Closed
Labels

Comments

@Conduitry
Copy link
Member

If a component has

<script>
  export let foo = undefined;
</script>

then instantiating the component without a foo prop shouldn't cause a warning in dev mode. This seems to affect only cases where undefined is the default value - other default values work fine.

@Conduitry Conduitry added the bug label May 1, 2019
@Conduitry
Copy link
Member Author

I believe there's a bug when determining the initialized declarations in a given scope:

diff --git a/src/compile/utils/scope.ts b/src/compile/utils/scope.ts
index 20cca46c..6488986d 100644
--- a/src/compile/utils/scope.ts
+++ b/src/compile/utils/scope.ts
@@ -75,12 +75,10 @@ export class Scope {
 		if (node.kind === 'var' && this.block && this.parent) {
 			this.parent.add_declaration(node);
 		} else if (node.type === 'VariableDeclaration') {
-			const initialised = !!node.init;
-
 			node.declarations.forEach((declarator: Node) => {
 				extract_names(declarator.id).forEach(name => {
 					this.declarations.set(name, node);
-					if (initialised) this.initialised_declarations.add(name);
+					if (declarator.init) this.initialised_declarations.add(name);
 				});
 			});
 		} else {

In the AST, init is a property on the individual VariableDeclarators, not on the VariableDeclaration. I'm not sure whether this has any impact on other things in the code. None that I've seen so far.

Rich-Harris added a commit that referenced this issue May 4, 2019
Fix determining which props need a value in dev mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant