Skip to content

[babel-generator] Generated code doesn’t match with source with input source-maps #5408

@alloy

Description

@alloy

Input Code

I’ve put up a repo here

The relevant code is here

Expected Behavior

I would have expected the source-map from babel-generator to map from the original TypeScript source to the generated JS.

Current Behavior

The source-map doesn’t appear to have any relation to the original code.

Here are some examples of the code looked-up through the source-maps:

 Original: import * as React fr
Transform: var React=require("
 Generate: "use strict";

 Original: function MyComponent
Transform: function MyComponen
 Generate:  require("react");

As you can see, the transform step does a good job of mapping to the original code, but the generate step just produces something completely different.

Context

I’m trying to use TypeScript for our React Native project and have inline source-maps propagate properly through Babel. I would prefer to not write the intermediate JS (produced by tsc) to disk.

I’m not sure if I’m doing something wrong, if this has to do with how React Native uses transform and the generator, or if there’s a bug with babel-generator.

Your Environment

software version
Babel 6.23.1
node 6.2.1
npm 4.1.1
Operating System macOS 10.12.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: sourcemapsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: generator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions