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

Allow unicode characters in type name #279

Open
zhangciwu opened this issue Mar 4, 2020 · 7 comments · May be fixed by #539
Open

Allow unicode characters in type name #279

zhangciwu opened this issue Mar 4, 2020 · 7 comments · May be fixed by #539

Comments

@zhangciwu
Copy link
Contributor

// Rest: a-zA-Z | _ | $ | 0-9

The member of type name is restricted to only english letters (and some symbol)
Typescript now allows unicode characters (doc link)

So, modify this function to allow unicode characters in type name, or as an option?

@zhangciwu
Copy link
Contributor Author

zhangciwu commented Mar 4, 2020

My scenario: title value is in full chinese, so the result typename is blank, and error happens:

SyntaxError: Declaration or statement expected. (8:1)
   6 | */
   7 | 
>  8 | export type  = string
     | ^

(Maybe another bug to fix: do not generate blank type name)

@zhangciwu
Copy link
Contributor Author

A minimium schema would cause this error:

    {
            "type": "object",
            "title": "呵呵",
            "properties": {
                "some_key": {
                    "type": "string",
                    "title": "哈哈"
                }
            }
        }

@bcherny
Copy link
Owner

bcherny commented Mar 8, 2020

Sounds good to me! Want to put up a Pull Request?

@zhangciwu
Copy link
Contributor Author

Fix the blank name bug in #280

Allow unicode is a little complicated, would be later

@bcherny
Copy link
Owner

bcherny commented Mar 10, 2020

Thanks for the fix, but I think supporting Unicode (as you suggested) could be a better way to do it. What issues are you running into?

@zhangciwu
Copy link
Contributor Author

Got a doc: Valid JavaScript variable names in ES2015
Maybe using this code provided in this page to judge a string is a valid identifier is comprehensive, but it's not packed into npm, and while I found some packs:

https://github.com/purplecabbage/valid-identifier
https://github.com/YerkoPalma/is-valid-identifier
https://github.com/SteveWestbrook/is-valid-var-name

First download for most times, but seems not active; others are not widely adopted (npm downloads)
A little hard to choose

@iansw246
Copy link
Contributor

I am working on this.

I wanted to confirm that this project targets ES5. I'm considering using Unicode aware regex, but it appears to be only supported from ES2015.

If using ES5, I found https://github.com/mathiasbynens/regexpu.

Additionally, are there any concerns about backwards compatibility or previously generated names?

@iansw246 iansw246 linked a pull request Jul 18, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants