Socket
Socket
Sign inDemoInstall

6to5-core

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

6to5-core - npm Package Compare versions

Comparing version 2.13.0 to 2.13.1

59

lib/6to5/transformation/transformers/es6-let-scoping.js

@@ -60,2 +60,3 @@ "use strict";

exports.Program =
exports.BlockStatement = function (block, parent, scope, context, file) {

@@ -86,2 +87,3 @@ if (!t.isLoop(parent)) {

this.outsideLetReferences = {};
this.hasLetReferences = false;
this.letReferences = {};

@@ -100,6 +102,11 @@ this.body = [];

// this is a block within a `Function` so we can safely leave it be
if (t.isFunction(this.parent)) return;
var needsClosure = this.getLetReferences();
this.checkTDZ();
var needsClosure = this.getLetReferences();
// this is a block within a `Function/Program` so we can safely leave it be
if (t.isFunction(this.parent) || t.isProgram(this.block)) return;
// we can skip everything
if (!this.hasLetReferences) return;
if (needsClosure) {

@@ -116,2 +123,44 @@ this.needsClosure();

LetScoping.prototype.checkTDZ = function () {
var state = {
letRefs: this.letReferences,
file: this.file
};
traverse(this.block, {
enter: function (node, parent, scope, context, state) {
if (!t.isIdentifier(node)) return;
if (!t.isReferenced(node, parent)) return;
var declared = state.letRefs[node.name];
if (!declared) return;
// declared node is different in this scope
if (scope.get(node.name, true) !== declared) return;
var declaredLoc = declared.loc;
var referenceLoc = node.loc;
if (!declaredLoc || !referenceLoc) return;
// does this reference appear on a line before the declaration?
var before = referenceLoc.start.line < declaredLoc.start.line;
if (referenceLoc.start.line === declaredLoc.start.line) {
// this reference appears on the same line
// check it appears before the declaration
before = referenceLoc.start.col < declaredLoc.start.col;
}
if (before) {
throw state.file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized");
}
}
}, this.scope, state);
};
/**
* Description
*/
LetScoping.prototype.remap = function () {

@@ -246,4 +295,8 @@ var letRefs = this.letReferences;

_.extend(this.letReferences, keys);
this.hasLetReferences = true;
}
// no let references so we can just quit
if (!this.hasLetReferences) return;
// set let references to plain var references

@@ -250,0 +303,0 @@ standardiseLets(declarators);

@@ -10,2 +10,5 @@ "use strict";

// this is to avoid triggering the TDZ detection
node.id.loc = null;
var declar = t.variableDeclaration("let", [

@@ -12,0 +15,0 @@ t.variableDeclarator(node.id, t.toExpression(node))

2

package.json
{
"name": "6to5-core",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "2.13.0",
"version": "2.13.1",
"author": "Sebastian McKenzie <sebmck@gmail.com>",

@@ -6,0 +6,0 @@ "homepage": "https://6to5.org/",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc