BVB Source Codes

reactide Show tdz.js Source code

Return Download reactide: download tdz.js Source code - Download reactide Source code - Type:.js
  1. "use strict";
  2.  
  3. exports.__esModule = true;
  4. exports.visitor = undefined;
  5.  
  6. var _babelTypes = require("babel-types");
  7.  
  8. var t = _interopRequireWildcard(_babelTypes);
  9.  
  10. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  11.  
  12. function getTDZStatus(refPath, bindingPath) {
  13.   var executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath);
  14.  
  15.   if (executionStatus === "before") {
  16.     return "inside";
  17.   } else if (executionStatus === "after") {
  18.     return "outside";
  19.   } else {
  20.     return "maybe";
  21.   }
  22. }
  23.  
  24. function buildTDZAssert(node, file) {
  25.   return t.callExpression(file.addHelper("temporalRef"), [node, t.stringLiteral(node.name), file.addHelper("temporalUndefined")]);
  26. }
  27.  
  28. function isReference(node, scope, state) {
  29.   var declared = state.letReferences[node.name];
  30.   if (!declared) return false;
  31.  
  32.   return scope.getBindingIdentifier(node.name) === declared;
  33. }
  34.  
  35. var visitor = exports.visitor = {
  36.   ReferencedIdentifier: function ReferencedIdentifier(path, state) {
  37.     if (!this.file.opts.tdz) return;
  38.  
  39.     var node = path.node,
  40.         parent = path.parent,
  41.         scope = path.scope;
  42.  
  43.  
  44.     if (path.parentPath.isFor({ left: node })) return;
  45.     if (!isReference(node, scope, state)) return;
  46.  
  47.     var bindingPath = scope.getBinding(node.name).path;
  48.  
  49.     var status = getTDZStatus(path, bindingPath);
  50.     if (status === "inside") return;
  51.  
  52.     if (status === "maybe") {
  53.       var assert = buildTDZAssert(node, state.file);
  54.  
  55.       bindingPath.parent._tdzThis = true;
  56.  
  57.       path.skip();
  58.  
  59.       if (path.parentPath.isUpdateExpression()) {
  60.         if (parent._ignoreBlockScopingTDZ) return;
  61.         path.parentPath.replaceWith(t.sequenceExpression([assert, parent]));
  62.       } else {
  63.         path.replaceWith(assert);
  64.       }
  65.     } else if (status === "outside") {
  66.       path.replaceWith(t.throwStatement(t.inherits(t.newExpression(t.identifier("ReferenceError"), [t.stringLiteral(node.name + " is not defined - temporal dead zone")]), node)));
  67.     }
  68.   },
  69.  
  70.  
  71.   AssignmentExpression: {
  72.     exit: function exit(path, state) {
  73.       if (!this.file.opts.tdz) return;
  74.  
  75.       var node = path.node;
  76.  
  77.       if (node._ignoreBlockScopingTDZ) return;
  78.  
  79.       var nodes = [];
  80.       var ids = path.getBindingIdentifiers();
  81.  
  82.       for (var name in ids) {
  83.         var id = ids[name];
  84.  
  85.         if (isReference(id, path.scope, state)) {
  86.           nodes.push(buildTDZAssert(id, state.file));
  87.         }
  88.       }
  89.  
  90.       if (nodes.length) {
  91.         node._ignoreBlockScopingTDZ = true;
  92.         nodes.push(node);
  93.         path.replaceWithMultiple(nodes.map(t.expressionStatement));
  94.       }
  95.     }
  96.   }
  97. };
downloadtdz.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top