Comments (4)
The behavior of the compatibility semantics (as I understand it) is as follows:
When a function body is instantiated, it looks for functions declared in blocks inside of the body which could be replaced with var
declarations of the same name without causing an early error. This replacement does not actually occur, but an additional binding may be created. Essentially this requirement means that the new binding may not conflict with any lexical bindings in the block's scope or any containing scope, up to and including the scope in which the function's parameters are declared.
For such functions, a var-scoped binding is created in the function body's scope, in addition to the lexical binding created in the block containing the function declaration. This additional binding is initially undefined. When the function declaration statement is executed, instead of the statement doing nothing (recall that function declarations are hoisted to the top of the containing block), the statement will fetch the value of the normal, lexical binding created by the declaration and set the additional var-scoped binding to that value.
This can can lead to some surprising behavior. For example, the following snippet prints 0
with no errors (per spec, although I'm not aware of any correct implementations at the moment):
(function(){
{
f = 0;
function f(){};
}
console.log(f);
})();
Note also that there is currently a spec bug, which I just reported, which means that none of this will actually happen.
from escope.
It looks like a bug to me.
I guess escope should use this.currentScope().variableScope
instead of this.currentScope()
at this line: https://github.com/estools/escope/blob/master/src/referencer.js#L292
from escope.
Ah, there is a comment above the line...
from escope.
I don't think there's anything wrong with the current behaviour. Even if it may work while not being recognised by this tool, you should strife to write valid code that does not rely on being executed in a legacy environment anyway.
So if this feature should be built into escope, it should definitively be hidden behind a flag.
from escope.
Related Issues (20)
- Function Expression
- Error on ImportDeclaration HOT 1
- Update scope manager scopes once it was created HOT 2
- Add support for label scoping
- New escope-demo (not a bug)
- Add node.body check before attempting to vist children HOT 8
- Variables from global scope have empty references array
- Drop `es6-map`. HOT 1
- Function scope arguments variable HOT 1
- Drop using require'd assert in favour of just throwing an error
- Enter the version directly in index.js
- Problem with unused library functions
- let declaration treated as var declaration HOT 1
- Can't locate variable within named function's scope when function assigned to other variable HOT 4
- Function declarations attached to block scope? HOT 1
- Another version of escope HOT 1
- what does 'through' in escope mean? HOT 1
- Maybe i find a bug in escope ?
- Is ES6 parameter scope not supported? HOT 1
- JSDoc unavailable: 404 error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from escope.