-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Enable nested namespace (#951) #2105
Conversation
Sorry for taking some time to get to this, but thanks for the PR! I'm a little hesitant though to be doing this sort of parsing of the input string when the parsing isn't too too rigorous (it's just splitting on something). I think it'd be better if we could enhance the syntax of the attribute itself to avoid implicitly splitting on dots, for example providing a list of nested namespaces or something like |
Hm, that makes sense. Let me try it. |
I let the parser accept the namespace specification like #[wasm_bindgen(js_namespace = ["nestedNamespace", "InnerClass"])] or #[wasm_bindgen(js_namespace = someNamespace)] so that the backward compatibility is maintained. I found that one test fails, but it fails even for the original commit. In addition, |
I'd like to provide Monico Editor bindings as an example taggartsoftware/ts2rs#1, but it needs nested namespace support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I've finally gotten around to review, sorry again! I've got one small nit, but other than that can the documentation for js_namespace
be updated as well?
crates/macro-support/Cargo.toml
Outdated
@@ -17,7 +17,7 @@ extra-traits = ["syn/extra-traits"] | |||
strict-macro = [] | |||
|
|||
[dependencies] | |||
syn = { version = '1.0', features = ['visit'] } | |||
syn = { version = '1.0', features = ['full', 'visit'] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, how come this was added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I included this because the document of syn
says that ExprArray
requires the "full"
feature. But, I now checked that the entire crate seems to work even without this "full"
feature specification. Does it have something to do with how the features
is applied for each sub-crate? Anyway I think the dependencies should be included here..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!
Sure, will do! |
Thanks again! |
I started to be afraid that my PR breaks the backward compatibility, at least as long as Of course, this is a kind of "composite" problem among |
That issue is unrelated. The error was about wasm-bindgen from almost 2 years ago missing the |
I now notice the rule for the version field. I did some experiments and it seems that |
The ABI for wasm-bindgen-specific structures changes between each release is expected, this is why the CLI version must match the library version. @hajifkd can you explain more why you think this is an issue? |
@alexcrichton Thank you! Well, my concern was following. First, this code,
wasm_bindgen macro with the certain version of the ABI. Thus, if, say, a crate, called A, were dependent of two crates, B and C, and the crate B were expanded by wasm_bindgen whose version is, for instance, 0.2.60 , and the other crate were by 0.2.63 , the expanded codes would include different binary code. Then, no version of wasm_bindgen_cli could process the code of A appropriately, since two different ABIs would be mixed.
However, now I think that my understanding of the version resolution procedure of But there is still one point I do not understand. In rustwasm/wasm-pack#853, two different version of |
Yes Cargo should only allow one version of wasm-bindgen per crate graph. I don't understand how two entries for |
@hajifkd Cargo guarantees that there will be only one version of a package (unless there is a major version bump). For major version bumps, we haven't run into that problem yet (since we've been on 0.2 for a long time), but we would probably just tell users "don't mix different major versions of wasm-bindgen". The issue with rustwasm/wasm-pack#853 is because they were specifying wasm-bindgen as a git repo, not a Cargo version, so it's unrelated. |
Ah, I see. If there is a major version bump, Cargo allows for different versions to exist. I just thought opposite but now I understand it does not make sense. Thank you! |
* Enable nested namespace (rustwasm#951) * Specify the namespace as array (rustwasm#951) * added an example to the document Co-authored-by: Alex Crichton <[email protected]>
I let the macro parser accept
String
instead ofIdent
forjs_namespace
. The instance method of the class in a namespace is associated to the rusttype
which has the same name as the JS class without the namespace.