|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
939 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | exports.__esModule = true;
|
|---|
| 4 |
|
|---|
| 5 | const pattern = /(^|[;})])\s*(export|import)((\s+\w)|(\s*[{*=]))|import\(/m;
|
|---|
| 6 | /**
|
|---|
| 7 | * detect possible imports/exports without a full parse.
|
|---|
| 8 | *
|
|---|
| 9 | * A negative test means that a file is definitely _not_ a module.
|
|---|
| 10 | * A positive test means it _could_ be.
|
|---|
| 11 | *
|
|---|
| 12 | * Not perfect, just a fast way to disqualify large non-ES6 modules and
|
|---|
| 13 | * avoid a parse.
|
|---|
| 14 | * @type {import('./unambiguous').test}
|
|---|
| 15 | */
|
|---|
| 16 | exports.test = function isMaybeUnambiguousModule(content) {
|
|---|
| 17 | return pattern.test(content);
|
|---|
| 18 | };
|
|---|
| 19 |
|
|---|
| 20 | // future-/Babel-proof at the expense of being a little loose
|
|---|
| 21 | const unambiguousNodeType = /^(?:(?:Exp|Imp)ort.*Declaration|TSExportAssignment)$/;
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * Given an AST, return true if the AST unambiguously represents a module.
|
|---|
| 25 | * @type {import('./unambiguous').isModule}
|
|---|
| 26 | */
|
|---|
| 27 | exports.isModule = function isUnambiguousModule(ast) {
|
|---|
| 28 | return ast.body && ast.body.some((node) => unambiguousNodeType.test(node.type));
|
|---|
| 29 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.