Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String enums are converted to externs with empty strings enums #1412

Open
zuhairtaha opened this issue Dec 8, 2022 · 5 comments
Open

String enums are converted to externs with empty strings enums #1412

zuhairtaha opened this issue Dec 8, 2022 · 5 comments

Comments

@zuhairtaha
Copy link

If we have this enum

declare enum IOption {
  Read = 'read',
  Write = 'write'
}

The generated extern is

/** @enum {string} */
var IOption = {
  Read: '',
  Write: '',
};

It should be

/** @enum {string} */
var IOption = {
  Read: 'read',
  Write: 'write',
};
@mprobst
Copy link
Contributor

mprobst commented Dec 8, 2022 via email

@zuhairtaha
Copy link
Author

zuhairtaha commented Dec 8, 2022

I'm converting chrome types to closure compiler externs using tsickle.
There are some enums like chrome.declarativeNetRequest.RuleActionType.BLOCK which should be a string, but the issue is I'm getting empty string at the compiled code

@mprobst
Copy link
Contributor

mprobst commented Dec 8, 2022 via email

@zuhairtaha
Copy link
Author

Here is an use case
After generating externs for chrome types the RuleActionType enum will be

/** @enum {string} */
chrome.declarativeNetRequest.RuleActionType = {
  BLOCK: '',
  REDIRECT: '',
  ALLOW: '',
  UPGRADE_SCHEME: '',
  MODIFY_HEADERS: '',
  ALLOW_ALL_REQUESTS: '',
};

Then I run closure compiler to compile this javascript code

void chrome.declarativeNetRequest.updateDynamicRules({
  addRules: [
    {
      id: 1,
      priority: 1,
      action: {
        type: chrome.declarativeNetRequest.RuleActionType.MODIFY_HEADERS,
        responseHeaders: [
          {
            header: "Access-Control-Allow-Origin",
            operation: chrome.declarativeNetRequest.HeaderOperation.SET,
            value: "*"
          }
        ]
      },
      condition: {
        urlFilter: "<all_urls>",
        resourceTypes: [chrome.declarativeNetRequest.ResourceType.MAIN_FRAME]
      }
    }
  ],
  removeRuleIds: [1]
});

The issue is that closure compiler will replace chrome.declarativeNetRequest.RuleActionType.MODIFY_HEADERS with an empty string

@mprobst
Copy link
Contributor

mprobst commented Dec 8, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants