UNPKG

@marko/translator-default

Version:
46 lines (42 loc) 1.44 kB
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;var _babelUtils = require("@marko/babel-utils"); var _compiler = require("@marko/compiler"); var _withPreviousLocation = _interopRequireDefault(require("../../util/with-previous-location")); const kHadAssignment = Symbol();var _default = exports.default = { AssignmentExpression(path, state) { if ( !state[kHadAssignment] && path.node.left.type === "Identifier" && path.node.left.name === "data") { state[kHadAssignment] = true; let root = path.parentPath; while (root.parentPath.type !== "Program") { root = root.parentPath; } root.insertBefore( _compiler.types.markoScriptlet([ _compiler.types.variableDeclaration("var", [ _compiler.types.variableDeclarator(_compiler.types.identifier("data"))] )] ) ); } }, ReferencedIdentifier(path, state) { if ( !state[kHadAssignment] && path.node.name === "data" && !path.scope.hasBinding("data")) { (0, _babelUtils.diagnosticDeprecate)(path, { label: "The 'data' variable is deprecated. Use 'input' instead.", fix() { path.replaceWith( (0, _withPreviousLocation.default)(_compiler.types.identifier("input"), path.node) ); } }); } } };