Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build introduces overlapping variable names #5862

Closed
zawys opened this issue Feb 17, 2021 · 2 comments
Closed

Build introduces overlapping variable names #5862

zawys opened this issue Feb 17, 2021 · 2 comments

Comments

@zawys
Copy link

zawys commented Feb 17, 2021

🐛 Bug report

parcel build produces invalid JS.

🎛 Configuration (.babelrc, package.json, cli command)

.babelrc: not present

package.json:

{
  "name": "parcel_minification_bug_demo",
  "version": "1",
  "main": "dist/extension.js",
  "targets": {
    "main": {
      "includeNodeModules": {
        "vscode": false
      }
    }
  },
  "scripts": {
    "clean": "rm -rf out packages dist .parcel-cache",
    "bundle": "parcel build --target main --no-cache --no-optimize src/extension.ts",
    "build": "yarn run clean && yarn run bundle"
  },
  "devDependencies": {
    "@parcel/transformer-typescript-tsc": "^2.0.0-nightly.599",
    "@types/vscode": "^1.48.0",
    "parcel": "^2.0.0-nightly.597",
    "typescript": "^4.0.2"
  },
  "dependencies": {}
}

.parcelrc:

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.{ts,tsx}": ["@parcel/transformer-typescript-tsc"]
  }
}

src/extension.ts

import * as vscode from "vscode";

export function register(): void {
  const commands: any[] = [];
  for (const x of commands) {
    vscode.commands.registerCommand("", () => { });
  }
}

CLI command: yarn run build

🤔 Expected behavior

Working code.

😯 Current behavior

Following is produced in dist/extension.js:

var commands = require("vscode").commands;
function register() {
  var commands = [];
  for (var _i = 0, commands_1 = commands; _i < commands_1.length; _i++) {
    var x = commands_1[_i];
    commands.registerCommand("", function () {});
  }
}
exports.register = register;

//# sourceMappingURL=extension.js.map

The import commands is overlapped by the variable in the function while the TypeScript code is valid. This causes an exception at runtime (undefined is no function).

🔦 Context

I can reproduce the bug with parcel 2.0.0-beta.1 and @parcel/transformer-typescript-tsc 2.0.0-nightly.1. However, the code worked previously so it might be due to a change in a dependency of parcel.

💻 Code sample

See above and parcel_bug_demo.zip (contains the files above + yarn.lock).

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.597
Node 14.15.4
npm/Yarn Yarn 1.22.5
Operating System Fedora 33

🔗 Possibly related issues

#5746 #5657 #5091

@zawys
Copy link
Author

zawys commented Feb 21, 2021

From a developer perspective, a workaround would be to avoid star imports and instead choose explicitly what to import (import { commands } from "vscode";). Then no latent variables are introduced during build for that.

@devongovett
Copy link
Member

I don't think this should be an issue anymore in beta 3 and later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants