TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

add module:ignore option

Open bidiboom opened this issue 11 years ago • 8 comments

Hi, when using ES6 module spec and try to generate ES5 code, the compiler invite me to specify a module type for the output : amd|commonjs. Is it possible to add ignore like in babeljs so we can concatenate output into a single file without having to use an extra tool to do the operation please ?

bidiboom avatar May 29 '15 09:05 bidiboom

can you specify more details on the generated output. so how would import * from "module" or export default function foo(){} be emitted?

mhegazy avatar May 29 '15 16:05 mhegazy

Hello!

it seems they just strip module information as seen here in documentation : https://babeljs.io/docs/usage/modules/

They gave an example :

import foo from "foo";

export function bar() {
  return foo("foobar");
}

Will give :

function bar() {
  return foo("foobar");
}

It is probably not as robust as you may want.

bidiboom avatar Jun 24 '15 08:06 bidiboom

I am not sure i understand how this is meant to be used later. looking at babel's output in this case:

import {foo  as foobar} from "foo";

export function bar() {
  return foobar("foobar");
}

emits with --m ignore:

"use strict";

exports.bar = bar;
Object.defineProperty(exports, "__esModule", {
  value: true
});

var foobar = require("foo").foo;

function bar() {
  return foobar("foobar");
}

so you still have a call to require; if that is fine, just use --m commonjs.

mhegazy avatar Jun 24 '15 17:06 mhegazy

Hi,

let me talk to you about my use case, it will probably help to understand why i hope to have this kind of feature (and for for your time by the way!). I'm coding using ES6 module and i want to be able to produce ES5 code without having to use commonjs or AMD module things the same way we can do using Typescript module.

For now, i must use a third party solution (babel for example) in order to have ES5 code without this external module things. Since we can do it with Typescript module, i was hopping that we can also ask to the compiler to output ES5 code without having to depend on commonjs/amd/...

To come back to mhegazy, i didn't included a librairie to handle those require calls. They may be changed it, i'll check this point to see if the ES5 code rely on another component in order to load

bidiboom avatar Jul 20 '15 07:07 bidiboom

Hi @bidiboom, are you asking for us to concatenate the code of imported modules in place of loading them at runtime?

DanielRosenwasser avatar Jul 20 '15 08:07 DanielRosenwasser

@bidiboom what is the difference between --m ignore and --m commonjs in your scenario ?

mhegazy avatar Jul 20 '15 18:07 mhegazy

Hi!

Sorry for responding this late. Wasn't around for some time. Actually after reading some other opened items i saw this one https://github.com/Microsoft/TypeScript/issues/17 which is exactly what i want to achieve with this kind of options.

I suggested the module:ignore to achieve what is described in the ticket (be able to concatenate every file into a single one).

bidiboom avatar Sep 11 '15 07:09 bidiboom

i see. closing this then in favor of #17.

mhegazy avatar Sep 11 '15 17:09 mhegazy