google / clasp

🔗 Command Line Apps Script Projects
https://developers.google.com/apps-script/guides/clasp
Apache License 2.0
4.59k stars 428 forks source link

Map objects are not being handled properly during conversion from typescript to google apps script #911

Open PedroHBrasil opened 2 years ago

PedroHBrasil commented 2 years ago

(Note: Non-breaking issues are likely not to be prioritized. Please consider a PR in addition to your issue)

Expected Behavior

When pushing a project written in TypeScript, it would be expected that a for...of loop applied on a map iterator (such as the return of map.entries() and map.keys()) would result on an executable loop on google apps script.

Also, the piece of code [...map_object.entries()] should return an array that contains sub-arrays filled with key-value pairs (like [[key1, value1], [key2, value2], ... , [keyN, valueN]]).

Actual Behavior

When pushing a project, for...of loops applied to map iterators have their code replaced to non-executable loops (like for (var _i = 0, _a = map_object.entries(); _i < _a.length; _i++)

Also, the convertion does not handle the piece of code [...map_object.entries()] properly, since it's converted to a piece of code that returns an empty array (__spreadArray([], data_map.entries(), true)).

Steps to Reproduce the Problem

  1. On a GAS project, add a .ts file.
  2. Create a map object, such as const map_object = new Map();
  3. Add an entry to the map object, such as map_object.set("key1", "value1");.
  4. Write a for...of loop such as for (const entry of map_object.entries()).
  5. Inside the loop, write Logger.log(entry);.
  6. Outside the loop, add the line Logger.log([...map_object.entries()]);.
  7. Push the project to GAS.
  8. Check and run the code on GAS and check the log.

Specifications

muddi900 commented 2 years ago

I have also encountered this issue

I don't know why clasp can't just compile to ES6. This issue can easily be mitigated

muddi900 commented 2 years ago

The workaround is to use typescript and add this to the tsconfig.json:

{
    "compilerOptions": {
      "lib": ["esnext"],
      "experimentalDecorators": true,
      "target": "ES2015"
    }
}