326 // Global variables are implicitly always scope variables too.
327 if (isGlobal) {
328 flags |= IS_SCOPE;
329 }
330
331 if (lc.getCurrentFunction().isProgram()) {
332 flags |= IS_PROGRAM_LEVEL;
333 }
334
335 final boolean isParam = (flags & KINDMASK) == IS_PARAM;
336 final boolean isVar = (flags & KINDMASK) == IS_VAR;
337
338 if (symbol != null) {
339 // Symbol was already defined. Check if it needs to be redefined.
340 if (isParam) {
341 if (!isLocal(function, symbol)) {
342 // Not defined in this function. Create a new definition.
343 symbol = null;
344 } else if (symbol.isParam()) {
345 // Duplicate parameter. Null return will force an error.
346 throw new AssertionError("duplicate parameter");
347 }
348 } else if (isVar) {
349 if (isBlockScope) {
350 // Check redeclaration in same block
351 if (symbol.hasBeenDeclared()) {
352 throwParserException(ECMAErrors.getMessage("syntax.error.redeclare.variable", name), origin);
353 } else {
354 symbol.setHasBeenDeclared();
355 // Set scope flag on top-level block scoped symbols
356 if (function.isProgram() && function.getBody() == block) {
357 symbol.setIsScope();
358 }
359 }
360 } else if ((flags & IS_INTERNAL) != 0) {
361 // Always create a new definition.
362 symbol = null;
363 } else {
364 // Found LET or CONST in parent scope of same function - s SyntaxError
365 if (symbol.isBlockScoped() && isLocal(lc.getCurrentFunction(), symbol)) {
366 throwParserException(ECMAErrors.getMessage("syntax.error.redeclare.variable", name), origin);
|
326 // Global variables are implicitly always scope variables too.
327 if (isGlobal) {
328 flags |= IS_SCOPE;
329 }
330
331 if (lc.getCurrentFunction().isProgram()) {
332 flags |= IS_PROGRAM_LEVEL;
333 }
334
335 final boolean isParam = (flags & KINDMASK) == IS_PARAM;
336 final boolean isVar = (flags & KINDMASK) == IS_VAR;
337
338 if (symbol != null) {
339 // Symbol was already defined. Check if it needs to be redefined.
340 if (isParam) {
341 if (!isLocal(function, symbol)) {
342 // Not defined in this function. Create a new definition.
343 symbol = null;
344 } else if (symbol.isParam()) {
345 // Duplicate parameter. Null return will force an error.
346 throwParserException(ECMAErrors.getMessage("syntax.error.duplicate.parameter", name), origin);
347 }
348 } else if (isVar) {
349 if (isBlockScope) {
350 // Check redeclaration in same block
351 if (symbol.hasBeenDeclared()) {
352 throwParserException(ECMAErrors.getMessage("syntax.error.redeclare.variable", name), origin);
353 } else {
354 symbol.setHasBeenDeclared();
355 // Set scope flag on top-level block scoped symbols
356 if (function.isProgram() && function.getBody() == block) {
357 symbol.setIsScope();
358 }
359 }
360 } else if ((flags & IS_INTERNAL) != 0) {
361 // Always create a new definition.
362 symbol = null;
363 } else {
364 // Found LET or CONST in parent scope of same function - s SyntaxError
365 if (symbol.isBlockScoped() && isLocal(lc.getCurrentFunction(), symbol)) {
366 throwParserException(ECMAErrors.getMessage("syntax.error.redeclare.variable", name), origin);
|