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

feat(imports): add doT template engine #1024

Merged
merged 6 commits into from
Jul 31, 2018
Merged

Conversation

stephenmathieson
Copy link
Member

@stephenmathieson stephenmathieson commented Jul 30, 2018

This patch adds the doT template engine to axe.imports. This is required for a runtime localization (a WIP feature).

We're continuing to use doT rather than replacing it with a maintained template engine because all of our rules/checks/messaging currently use it. Changing this now would be a very large task, which is outside of the scope of the feature I'm working on.

A lot of hackery was required to get this working, since doT doesn't expose a UMD wrapper that our build system supports. Rather than attempting to get our existing tooling to "unwrap" doT's custom UMD, I've decided to save a lot of time/effort and just wrap it in an IIFE. There are likely 1,000s of variations of UMD in the wild and it's unreasonable for us to attempt to support them all. The added IIFE method works in cases where the code functions exactly the same regarless of enviroment (this does not include libraries like Axios). IMHO the only reasonable solution to this problem is to use a proper bundler for building axe-core.

Reviewer checks

Required fields, to be filled out by PR reviewer(s)

  • Follows the commit message policy, appropriate for next version
  • Has documentation updated, a DU ticket, or requires no documentation change
  • Includes new tests, or was unnecessary
  • Code is reviewed for security by: @WilcoFiers

This patch adds the [`doT`](https://npmjs.org/dot) template engine to `axe.imports`. This is required for a runtime localization (a WIP feature).

A lot of hackery was required to get this working, since `doT` doesn't expose a UMD wrapper that our build system supports. Rather than attempting to get our existing tooling to "unwrap" `doT`'s custom UMD, I've decided to save a lot of time/effort and just wrap it in an IIFE. There are likely 1,000,000s of variations of UMD in the wild and it's unreasonable for us to attempt to support them all. The added IIFE method works in cases where the code functions exactly the same regarless of enviroment (this does not include libraries like Axios). IMHO the only reasonable solution to this problem is to use a proper bundler for building `axe-core`.
* @param {string} sourceUrl path to the distributable of the library
* @param {string} sourceCode source code for the library
* @param {Object} [options] Optional options
* @property {Boolean} umd Does the library contain a UMD wrapper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, what's the distinction between param and property here in jsdoc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property is a member of the above param


// If there was a global prior to our script, make sure we
// "save" it (think "$.noConflict()").
var __old_global__ = global["${global}"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two global variables in use here, so the code is a little hard to follow (the global passed in and the variable set to the current scope). How can you reset to the old global when it has been overwritten with a new variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The passed global is a library name. I'll rename to make that clearer.

To be sure its reset, see a few LOC below.

@dequelabs dequelabs deleted a comment from stephenmathieson Jul 31, 2018
WilcoFiers
WilcoFiers previously approved these changes Jul 31, 2018
isner
isner previously approved these changes Jul 31, 2018
@stephenmathieson stephenmathieson dismissed stale reviews from isner and WilcoFiers via 046d270 July 31, 2018 13:46
@stephenmathieson stephenmathieson merged commit f6f08d4 into develop Jul 31, 2018
@stephenmathieson stephenmathieson deleted the add-dot-runtime branch July 31, 2018 14:00
stephenmathieson added a commit that referenced this pull request Jul 31, 2018
* develop:
  feat(imports): add `doT` template engine (#1024)
  doc: ensure client is closed
  doc: fix comment
  doc: fix "parity" typo
  doc: ensure user starts chrome
  chore(package): auto-format *.ts files (#1029)
  build: replace babel-preset-es2015 with babel-preset-env (#1027)
  chore: remove `.jshintrc` files (#1028)
  chore: add `.npmrc` (#1026)
  chore: upgrade Prettier and run the formatter (#1030)
  doc(examples): add simple CDP example
  ci: Speed up builds by caching node_modules (#1025)
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

Successfully merging this pull request may close these issues.

4 participants