tslab icon indicating copy to clipboard operation
tslab copied to clipboard

Disallow definitions of variable with require or exports names

Open yunabe opened this issue 6 years ago • 3 comments

To bypass #1, tslab converts (1) TypeScript into ES2015 module JS with TS compiler, (2) then convert it into CommonJS module JS.

In (1), TypeScript does not check the colisions with require and exports because the output module is ES2015 (See checkCollisionWithRequireExportsInGeneratedCode in checker.ts of TypeScript). In (2), ts.transpile does not check anything.

Thus, tslab does not detect the colisions with require and exports in the current implementation.

yunabe avatar Sep 23 '19 12:09 yunabe

I'm seeing some odd behaviour and not sure if it's related to this or something separate?

If I have a cell which either runs:

import { _ } from "lodash"

...or...

var _ = require('lodash');

...and then a separate cell that tries to reference _, I get an error like:

1:1 - Cannot find name '_'.

I've only played around with a couple of combinations, but it doesn't seem to be specific to the lodash library or the name of the import.

A similar pair of cells with something simple like var _ = 1; and console.log(_); is fine

(On TSLab v1.0.15, jslab kernel)

athewsey avatar Apr 26 '21 10:04 athewsey

Hi Alex, I think that bug is unrelated to this bug.

Could you file a another bug? Also, I could not reproduce your problem in TypeScript kernel. It's great if you can include detailed information (e.g. your environments and the commands you executed) when you file a bug.

lodash

Thanks

yunabe avatar Apr 26 '21 13:04 yunabe

Done (#53) thanks... Definitely only affects the JS kernel, and could well be environment-related now I've had a chance to dig around a bit more!

athewsey avatar Apr 27 '21 16:04 athewsey