grant / ts2gas

A function that transpiles TypeScript to Google Apps Script.
http://npmjs.com/ts2gas
MIT License
88 stars 11 forks source link

Multi-line import statements creates invalid Apps Script #29

Closed byerun closed 5 years ago

byerun commented 5 years ago

Expected Behavior

Multi-line typescript import statements translated correctly

Actual Behavior

The translated Apps Script code is invalid

Steps to Reproduce the Problem

  1. Create a multi-line typscript import statement such as
    import {
    FinancialTransactionFromSpreadsheet,
    SpreadSheetDef
    } from "./financial.transaction.from.spreadsheet";
  2. Have clasp push to remote project

The translated code will have a "\n" embedded along with invalid lines:

//import {
\n  FinancialTransactionFromSpreadsheet,
  SpreadSheetDef
} from "./financial.transaction.from.spreadsheet";

Attempting to run the code will produce the error message Illegal character.

Specifications

takanakahiko commented 5 years ago

I think that this line is causing problems.

https://github.com/grant/ts2gas/blob/4f7827164187c6d8deb2c9a259b1312061f2ab0b/src/index.ts#L20

In general, replace( 'A', 'B' ) replaces A with B only once. Therefore, if an import statement exceeds two lines, you can not delete a line break completely.

See also : https://www.w3schools.com/jsref/jsref_replace.asp

So, I propose using regular expressions like replace( /\n/g , '\\n' ).

grant commented 5 years ago

Thanks for the report and fix.

30 was published with 1.6.1.

Please create a PR to update this dependency in clasp.

ardent42c commented 4 years ago

This is still happening with ts2gas 3.6.1 and clasp 2.3.0 ! was the fix rolled back??