UNPKG

1.67 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt The complete set of authors may be found
7 * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
8 * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
9 * Google as part of the polymer project is also subject to an additional IP
10 * rights grant found at http://polymer.github.io/PATENTS.txt
11 */
12Object.defineProperty(exports, "__esModule", { value: true });
13const analyzer = require("polymer-analyzer");
14/**
15 * Return whether an Analyzer document is a JavaScript document which was parsed
16 * as a module.
17 */
18function isEsModuleDocument(doc) {
19 return doc.type === 'js' &&
20 doc.parsedDocument
21 .parsedAsSourceType === 'module';
22}
23exports.isEsModuleDocument = isEsModuleDocument;
24/**
25 * Resolve an identifier being imported or exported to the feature it refers to.
26 */
27function resolveImportExportFeature(feature, identifier, doc) {
28 for (const kind of resolveKinds) {
29 const reference = new analyzer.ScannedReference(kind, identifier, feature.sourceRange, feature.astNode, feature.astNodePath);
30 const resolved = reference.resolve(doc);
31 if (resolved.feature !== undefined) {
32 return resolved;
33 }
34 }
35 return undefined;
36}
37exports.resolveImportExportFeature = resolveImportExportFeature;
38const resolveKinds = [
39 'element',
40 'behavior',
41 'element-mixin',
42 'class',
43 'function',
44 'namespace',
45];
46//# sourceMappingURL=es-modules.js.map
\No newline at end of file