-
Notifications
You must be signed in to change notification settings - Fork 2k
Add importMeta getter to derive importPath from modules. Fixes #5163 #5172
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7672da
Add importMeta getter to derive importPath from modules. Fixes #5163
kevinpschaaf fb741ee
Fix lint warning
kevinpschaaf 2128ebe
Fix test under shadydom. Slight logic refactor.
kevinpschaaf d9d3e43
Use Polymer.ResolveUrl.pathFromUrl
kevinpschaaf c8c9e24
Update docs.
kevinpschaaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,13 +409,33 @@ | |
*/ | ||
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); | ||
} else { | ||
const module = Polymer.DomModule && Polymer.DomModule.import(/** @type {PolymerElementConstructor} */ (this).is); | ||
this._importPath = module ? module.assetpath : '' || | ||
Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.importPath; | ||
if (module) { | ||
this._importPath = module ? module.assetpath : ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be just |
||
} else { | ||
this._importPath = Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.importPath; | ||
} | ||
} | ||
} | ||
return this._importPath; | ||
} | ||
|
||
/** | ||
* When an element definition is being loaded from an ES module, users | ||
* may override this getter to return the `import.meta` object from that | ||
* module, which will be used to derive the `importPath` for the element. | ||
* When implementing `importMeta`, users should not implement `importPath`. | ||
* | ||
* @return {!Object} The `import.meta` object for the element's module | ||
*/ | ||
static get importMeta() { | ||
return null; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
/** @type {HTMLTemplateElement} */ | ||
|
@@ -447,14 +467,13 @@ | |
_initializeProperties() { | ||
Polymer.telemetry.instanceCount++; | ||
this.constructor.finalize(); | ||
const importPath = this.constructor.importPath; | ||
// note: finalize template when we have access to `localName` to | ||
// avoid dependence on `is` for polyfilling styling. | ||
this.constructor._finalizeTemplate(/** @type {!HTMLElement} */(this).localName); | ||
super._initializeProperties(); | ||
// set path defaults | ||
this.rootPath = Polymer.rootPath; | ||
this.importPath = importPath; | ||
this.importPath = this.constructor.importPath; | ||
// apply property defaults... | ||
let p$ = propertyDefaults(this.constructor); | ||
if (!p$) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
use
resolveUrl.pathFromUrl