Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | exports.PatternMatchingHost = void 0;
|
---|
11 | const resolver_1 = require("./resolver");
|
---|
12 | /**
|
---|
13 | */
|
---|
14 | class PatternMatchingHost extends resolver_1.ResolverHost {
|
---|
15 | constructor() {
|
---|
16 | super(...arguments);
|
---|
17 | this._patterns = new Map();
|
---|
18 | }
|
---|
19 | addPattern(pattern, replacementFn) {
|
---|
20 | // Simple GLOB pattern replacement.
|
---|
21 | const reString = '^(' +
|
---|
22 | (Array.isArray(pattern) ? pattern : [pattern])
|
---|
23 | .map((ex) => '(' +
|
---|
24 | ex
|
---|
25 | .split(/[\/\\]/g)
|
---|
26 | .map((f) => f
|
---|
27 | .replace(/[\-\[\]{}()+?.^$|]/g, '\\$&')
|
---|
28 | .replace(/^\*\*/g, '(.+?)?')
|
---|
29 | .replace(/\*/g, '[^/\\\\]*'))
|
---|
30 | .join('[/\\\\]') +
|
---|
31 | ')')
|
---|
32 | .join('|') +
|
---|
33 | ')($|/|\\\\)';
|
---|
34 | this._patterns.set(new RegExp(reString), replacementFn);
|
---|
35 | }
|
---|
36 | _resolve(path) {
|
---|
37 | let newPath = path;
|
---|
38 | this._patterns.forEach((fn, re) => {
|
---|
39 | if (re.test(path)) {
|
---|
40 | newPath = fn(newPath);
|
---|
41 | }
|
---|
42 | });
|
---|
43 | return newPath;
|
---|
44 | }
|
---|
45 | }
|
---|
46 | exports.PatternMatchingHost = PatternMatchingHost;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.