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

Default export of anonymous function or class crashes compiler #3275

Closed
Conduitry opened this issue Jul 21, 2019 · 3 comments · Fixed by #6471
Closed

Default export of anonymous function or class crashes compiler #3275

Conduitry opened this issue Jul 21, 2019 · 3 comments · Fixed by #6471
Labels

Comments

@Conduitry
Copy link
Member

<script>
	export default function() {}
</script>
<script>
	export default class {}
</script>

Both of these should throw the usual A component cannot have a default export error, but instead they are crashing the compiler. The error in each case is TypeError: Cannot read property 'name' of null but it is coming from a different line.

Pretty low priority obviously, but still a bug.

@Conduitry Conduitry added the bug label Jul 21, 2019
@Conduitry
Copy link
Member Author

Seemingly fixed by:

diff --git a/src/compiler/compile/utils/scope.ts b/src/compiler/compile/utils/scope.ts
index 0255ac94..f170060f 100644
--- a/src/compiler/compile/utils/scope.ts
+++ b/src/compiler/compile/utils/scope.ts
@@ -18,7 +18,9 @@ export function create_scopes(expression: Node) {
 				});
 			} else if (/Function/.test(node.type)) {
 				if (node.type === 'FunctionDeclaration') {
-					scope.declarations.set(node.id.name, node);
+					if (node.id) {
+						scope.declarations.set(node.id.name, node);
+					}
 					scope = new Scope(scope, false);
 					map.set(node, scope);
 				} else {
@@ -90,7 +92,7 @@ export class Scope {
 					if (declarator.init) this.initialised_declarations.add(name);
 				});
 			});
-		} else {
+		} else if (node.id) {
 			this.declarations.set(node.id.name, node);
 		}
 	}

I don't know whether this indicates that we're doing something in the wrong order, or whether there are any other situations where we could get to these spots in the code with node.id being undefined.

@stale
Copy link

stale bot commented Jun 27, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@Conduitry
Copy link
Member Author

Fixed in 3.39.0.

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.

2 participants