Commit Graph

59 Commits

Author SHA1 Message Date
da9203142f Add applying of typedefs, remove generation of type aliases 2018-08-04 14:04:24 +03:00
c4dcaee1b9 Prepare to have targeted error diagnostics (#604)
This commit starts to add infrastructure for targeted diagnostics in the
`#[wasm_bindgen]` attribute, intended eventually at providing much better errors
as they'll be pointing to exactly the code in question rather than always to a
`#[wasm_bindgen]` attribute.

The general changes are are:

* A new `Diagnostic` error type is added to the backend. A `Diagnostic` is
  created with a textual error or with a span, and it can also be created from a
  list of diagnostics. A `Diagnostic` implements `ToTokens` which emits a bunch
  of invocations of `compile_error!` that will cause rustc to later generate
  errors.

* Fallible implementations of `ToTokens` have switched to using a new trait,
  `TryToTokens`, which returns a `Result` to use `?` with.

* The `MacroParse` trait has changed to returning a `Result` to propagate errors
  upwards.

* A new `ui-tests` crate was added which uses `compiletest_rs` to add UI tests.
  These UI tests will verify that our output improves over time and does not
  regress. This test suite is added to CI as a new builder as well.

* No `Diagnostic` instances are created just yet, everything continues to panic
  and return `Ok`, with the one exception of the top-level invocations of
  `syn::parse` which now create a `Diagnostic` and pass it along.

This commit does not immediately improve diagnostics but the intention is that
it is laying the groundwork for improving diagnostics over time. It should
ideally be much easier to contribute improved diagnostics after this commit!

cc #601
2018-08-01 17:15:27 -05:00
b7af4e3169 Add documentation and MDN links for webidl files. Fixes #513 (#581) 2018-07-29 09:12:36 -07:00
66bc98cc4b Fix mistakes/nits. 2018-07-25 18:08:57 +01:00
ba67089501 Some docs for functions in the parsing/codegen crates. 2018-07-25 11:42:01 +01:00
2ee80a6c44 Add some docs 2018-07-24 17:37:49 +01:00
b3ee71c20b WebIDL: Handle Invalid Enum Returns (#477)
* move ImportEnum attributes to a property

* borrow from_js_value argument

* make WebIDL enums non-exhaustive

* add more tests for WebIDL enums
2018-07-23 10:04:28 -05:00
9753f9150b Allow renaming exported functions into JS (#525)
Support the `js_name` attribute on exports as well as imports to allow exporting
types as camelCase instead of snake_case, for example.

Closes #221
2018-07-20 12:01:28 -05:00
9d27b44a4a Fix extra-traits feature (#491) 2018-07-17 10:28:44 -05:00
4cc069bd01 Clean up Some Clippy Warnings (#478)
* clippy: it is more idiomatic to loop over references to containers instead of using explicit iteration methods

* clippy: useless use of `format!`

* clippy: if/else is an expression

* clippy: use of  followed by a function call

* clippy: large size difference between variants

* clippy: redundant closure

* Revert "clippy: large size difference between variants"

This reverts commit 7e2e660dd47c9718126d1c45ae1caa632e287a14.

* Revert "clippy: it is more idiomatic to loop over references to containers instead of using explicit iteration methods"

This reverts commit 5c4804f790fc6a33a7a0f0d2aacdc4b98529b978.
2018-07-15 11:43:55 -05:00
51b9eb81e8 split const integers into signed and unsigned 2018-07-14 22:48:37 +02:00
80384d8da9 address my comments for #470 2018-07-13 22:36:51 -07:00
862e4c50f6 backend: add const to ast 2018-07-13 19:59:21 +02:00
a981dfd507 webidl: initial enum support
Add enum support to the WebIDL interface generator.
2018-07-10 20:28:34 -04:00
2d50d5209b Backend refactor (#411)
* remove BindgenAttrs from other backend::ast structs

This is primarily a tool for use with the macro crate. Most of
these attributes were ignored in the actual codegen, but a few
were still being used. This is confusing when trying to add
other sources for codegen (such as webidl and typescript).

* move parsing logic to macro crate

This makes the backend crate solely concerned with having an ast
for which we can generate code.
2018-07-07 12:20:31 -05:00
5a776c16b2 Forward attributes on type declaration to definition
This'll allow things like `#[derive(Clone)]` or `#[derive(Debug)]` to control
traits for these types.
2018-07-05 20:28:52 -07:00
e55af85edc Support by-value self methods (#348)
Refactor slightly to use the same internal support that the other reference
conversions are using.

Closes #329
2018-06-28 20:09:11 -05:00
9127a0419f rustfmt all the things 2018-06-27 22:42:34 -07:00
8fbf478058 Move some utility functions from the webidl crate into the backend crate 2018-06-25 10:45:53 -07:00
21fa3beabd backend: Add some trailing commas that rustfmt prefers 2018-06-25 10:45:53 -07:00
911a32c0d5 Add the #[wasm_bindgen(static_method_of = Class)] attribute
This is similar to `js_namespace` but translates into a static method on `Class`
rather than a free function. This allows us to have bindings to things like
`Object.keys` as `Object::keys`.
2018-06-25 10:45:53 -07:00
d79f982a01 Merge pull request #295 from kzvi/js-class-attr
add js_class attribute for defining what class an imported method is for
2018-06-22 21:38:14 -07:00
2cfffc65d7 add js_class attribute for defining what class an imported method is for 2018-06-22 12:12:43 -07:00
3bce3fb7a5 backend: Tidy up whitespace
* Remove trailing space on line.
* Ensure that there is a newline at the end of the file.
2018-06-22 11:14:33 -07:00
24f72c9680 backend: Remove unused import from ast module 2018-06-22 11:14:16 -07:00
5eda5504e9 Merge pull request #273 from FreeMasen/validate-ptr
Validate ptr
2018-06-19 16:45:31 -07:00
749ac6502f add ptr validation 2018-06-17 20:13:56 -05:00
0938858aa8 webidl: add support for static attributes 2018-06-15 12:22:14 -07:00
fe5cde8636 webidl: add support for static methods 2018-06-15 12:09:42 -07:00
639ccd53ce Merge pull request #269 from ohanar/webidl_constructor
webidl: add support for (named) constructors
2018-06-15 11:35:29 -07:00
19d6cf1488 Copy doc comments from Rust to JS (#265)
* backend comments complete

* better matching

* gen comments

* Add example

* Move test bindings gen to own fn

* move build step into build fn

* add fn to read js, refactor gen_bindings/test to allow for this

* Add comments test

* Update readmes

* add comments to travis

* fix broken tests

* +x on build.sh

* fix wbg cmd in build.sh

* Address fitzgen's comments
2018-06-15 09:20:56 -07:00
400015a061 webidl: refactor method/getter/getter generation 2018-06-14 14:39:04 -07:00
d065f4b05d webidl: add support for typedefs 2018-06-11 18:43:45 -07:00
7ea0a7cc26 webidl: emit methods for regular operations 2018-05-31 22:54:40 -07:00
c7819930b4 backend::ast: rustfmt 2018-05-31 22:52:43 -07:00
6885ea073e Only derive extra traits when the extra-traits feature is enabled 2018-05-29 11:24:40 -07:00
07d5afa268 backend: All AST types should implement Eq 2018-05-25 16:33:22 -07:00
018f083402 backend: All AST types should implement Debug 2018-05-25 16:20:07 -07:00
cfe7ebd463 Disallow structs w/ lifetime/type parameters
These can't work currently with wasm-bindgen, but maybe one day!

Closes #200
2018-05-21 09:13:17 -07:00
e76f5537e0 Upgrade to new versions of proc-macro2
Gonna get some nice spans back!
2018-05-21 07:29:34 -07:00
ca8809b4e9 Don't try to codegen static into an impl
Closes #194
2018-05-11 08:28:09 -07:00
06664b34ce Fix parsing some Rust keywords in attributes
Closes #193
2018-05-09 08:01:57 -07:00
b7bbcf5ea9 Fix compat with current nightly 2018-04-26 19:12:56 -07:00
412bebca72 Add support for version specifications
This commit adds a `#[wasm_bindgen(version = "...")]` attribute support. This
information is eventually written into a `__wasm_pack_unstable` section.
Currently this is a strawman for the proposal in ashleygwilliams/wasm-pack#101
2018-04-25 22:23:02 -07:00
7108206835 Implement readonly struct fields
Add support for `#[wasm_bindgen(readonly)]` which indicates that an exported
struct field is readonly and attempting to set it in JS will throw an exception.

Closes #151
2018-04-20 10:56:10 -07:00
c6f7d3dfd5 Fix methods returning Self
Rewrite any instance of `Self` to the name of the class

Closes #137
2018-04-19 18:43:37 -07:00
ce31859590 Generate accessors for public struct fields
Automatically infer public struct fields as "JS wants to access this" and
generate appropriate getters/setters for the field. At this time the field is
required to implement `Copy`, but we will probably want to relax that in the
future to at least encompass `JsValue` and maybe other `Clone` values as well.

Closes #121
2018-04-19 16:49:46 -07:00
5efde3abe9 Be sure to generate classes for empty structs
Closes #131
2018-04-16 08:05:18 -07:00
3999642f66 Merge remote-tracking branch 'upstream/master' into new 2018-04-15 01:50:23 +02:00
f45ce1f239 Do only use ConstructorToken when needed
Also removing some effectively dead code
2018-04-15 01:29:09 +02:00