|
409 | 409 | */ |
410 | 410 | static get importPath() { |
411 | 411 | if (!this.hasOwnProperty(JSCompiler_renameProperty('_importPath', this))) { |
| 412 | + const meta = this.importMeta; |
| 413 | + if (meta) { |
| 414 | + this._importPath = meta.url.slice(0, meta.url.lastIndexOf('/') + 1); |
| 415 | + } else { |
412 | 416 | const module = Polymer.DomModule && Polymer.DomModule.import(/** @type {PolymerElementConstructor} */ (this).is); |
413 | | - this._importPath = module ? module.assetpath : '' || |
414 | | - Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.importPath; |
| 417 | + if (module) { |
| 418 | + this._importPath = module ? module.assetpath : ''; |
| 419 | + } else { |
| 420 | + this._importPath = Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.importPath; |
| 421 | + } |
| 422 | + } |
415 | 423 | } |
416 | 424 | return this._importPath; |
417 | 425 | } |
418 | 426 |
|
| 427 | + /** |
| 428 | + * When an element definition is being loaded from an ES module, users |
| 429 | + * may override this getter to return the `import.meta` object from that |
| 430 | + * module, which will be used to derive the `importPath` for the element. |
| 431 | + * When implementing `importMeta`, users should not implement `importPath`. |
| 432 | + * |
| 433 | + * @return {!Object} The `import.meta` object for the element's module |
| 434 | + */ |
| 435 | + static get importMeta() { |
| 436 | + return null; |
| 437 | + } |
| 438 | + |
419 | 439 | constructor() { |
420 | 440 | super(); |
421 | 441 | /** @type {HTMLTemplateElement} */ |
|
447 | 467 | _initializeProperties() { |
448 | 468 | Polymer.telemetry.instanceCount++; |
449 | 469 | this.constructor.finalize(); |
450 | | - const importPath = this.constructor.importPath; |
451 | 470 | // note: finalize template when we have access to `localName` to |
452 | 471 | // avoid dependence on `is` for polyfilling styling. |
453 | 472 | this.constructor._finalizeTemplate(/** @type {!HTMLElement} */(this).localName); |
454 | 473 | super._initializeProperties(); |
455 | 474 | // set path defaults |
456 | 475 | this.rootPath = Polymer.rootPath; |
457 | | - this.importPath = importPath; |
| 476 | + this.importPath = this.constructor.importPath; |
458 | 477 | // apply property defaults... |
459 | 478 | let p$ = propertyDefaults(this.constructor); |
460 | 479 | if (!p$) { |
|
0 commit comments