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

Add importMeta getter to derive importPath from modules. Fixes #5163 #5172

Merged
merged 5 commits into from
Apr 3, 2018

Conversation

kevinpschaaf
Copy link
Member

@kevinpschaaf kevinpschaaf commented Apr 2, 2018

In order to determine the import path for ES modules, rather than implement static get importPath() and return the folder name of import.meta.url, users can implement the following getter (verbatim), and Polymer will use that when defined to determine the importPath:

static get importMeta() { return import.meta; }

Reference Issue

Fixes #5163

cc: @arthurevans to roll into 3.0 docs

Copy link
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

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

1 nit, other than that LGTM. The Travis build failed on a missing semicolon

this._importPath = module ? module.assetpath : '' ||
Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.importPath;
if (module) {
this._importPath = module ? module.assetpath : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be just module.assetpath, as the condition already asserted for module

Copy link
Member

@dfreedm dfreedm left a comment

Choose a reason for hiding this comment

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

LGTM in general

Copy link
Contributor

@sorvell sorvell left a comment

Choose a reason for hiding this comment

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

Let's update the docs for importPath to mention importMeta.

@@ -409,13 +409,30 @@
*/
static get importPath() {
if (!this.hasOwnProperty(JSCompiler_renameProperty('_importPath', this))) {
const meta = this.importMeta;
if (meta) {
this._importPath = meta.url.slice(0, meta.url.lastIndexOf('/') + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

use resolveUrl.pathFromUrl

@kevinpschaaf kevinpschaaf merged commit 689ff72 into master Apr 3, 2018
@kevinpschaaf kevinpschaaf deleted the 5163-kschaaf-import-meta branch April 3, 2018 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants