From 5faf2e9a693d10e1e689c42deec911083a35ddb2 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 21 Jun 2018 22:57:07 +0200 Subject: Properly distinguish between class expressions and declarations Introduce both types in the AST, and handle them properly in the code generator. Change-Id: I754ac0976de69009bdb8b203d890e4ec0ad03b30 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4compilerscanfunctions.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp') diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index eda0102844..8b8c385b84 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -225,6 +225,21 @@ bool ScanFunctions::visit(FunctionExpression *ast) } bool ScanFunctions::visit(ClassExpression *ast) +{ + enterEnvironment(ast, ContextType::Block, QStringLiteral("%Class")); + _context->isStrict = true; + _context->hasNestedFunctions = true; + if (!ast->name.isEmpty()) + _context->addLocalVar(ast->name.toString(), Context::VariableDeclaration, AST::VariableScope::Let); + return true; +} + +void ScanFunctions::endVisit(ClassExpression *) +{ + leaveEnvironment(); +} + +bool ScanFunctions::visit(ClassDeclaration *ast) { if (!ast->name.isEmpty()) _context->addLocalVar(ast->name.toString(), Context::VariableDeclaration, AST::VariableScope::Let); @@ -237,7 +252,7 @@ bool ScanFunctions::visit(ClassExpression *ast) return true; } -void ScanFunctions::endVisit(ClassExpression *) +void ScanFunctions::endVisit(ClassDeclaration *) { leaveEnvironment(); } -- cgit v1.2.3