@esportsplus/typescript 0.26.3 → 0.26.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,7 +28,7 @@ function applyPrepend(code, file, prepend) {
28
28
  if (prepend.length === 0) {
29
29
  return code;
30
30
  }
31
- let position = 0, text = prepend.join('\n') + '\n';
31
+ let position = 0;
32
32
  for (let i = 0, n = file.statements.length; i < n; i++) {
33
33
  let stmt = file.statements[i];
34
34
  if (ts.isImportDeclaration(stmt)) {
@@ -39,9 +39,9 @@ function applyPrepend(code, file, prepend) {
39
39
  }
40
40
  }
41
41
  if (position === 0) {
42
- return text + code;
42
+ return prepend.join('\n') + code;
43
43
  }
44
- return code.slice(0, position) + '\n' + text + code.slice(position);
44
+ return code.slice(0, position) + prepend.join('\n') + code.slice(position);
45
45
  }
46
46
  function hasPattern(code, patterns) {
47
47
  for (let i = 0, n = patterns.length; i < n; i++) {
@@ -52,11 +52,10 @@ function hasPattern(code, patterns) {
52
52
  return false;
53
53
  }
54
54
  function modify(code, file, pkg, options) {
55
- let { namespace } = options;
56
55
  if (!options.add && !options.namespace && !options.remove) {
57
56
  return code;
58
57
  }
59
- let add = options.add ? new Set(options.add) : null, found = imports.find(file, pkg), remove = options.remove ? new Set(options.remove) : null;
58
+ let { namespace } = options, add = options.add ? new Set(options.add) : null, found = imports.find(file, pkg);
60
59
  if (found.length === 0) {
61
60
  let statements = [];
62
61
  if (namespace) {
@@ -70,7 +69,7 @@ function modify(code, file, pkg, options) {
70
69
  }
71
70
  return statements.join('\n') + '\n' + code;
72
71
  }
73
- let specifiers = new Set();
72
+ let remove = options.remove ? new Set(options.remove) : null, specifiers = new Set();
74
73
  for (let i = 0, n = found.length; i < n; i++) {
75
74
  for (let [name, alias] of found[i].specifiers) {
76
75
  if (!remove || (!remove.has(name) && !remove.has(alias))) {
package/package.json CHANGED
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "type": "module",
39
39
  "types": "build/index.d.ts",
40
- "version": "0.26.3",
40
+ "version": "0.26.4",
41
41
  "scripts": {
42
42
  "build": "tsc && tsc-alias",
43
43
  "-": "-"
@@ -53,8 +53,7 @@ function applyPrepend(code: string, file: ts.SourceFile, prepend: string[]): str
53
53
  return code;
54
54
  }
55
55
 
56
- let position = 0,
57
- text = prepend.join('\n') + '\n';
56
+ let position = 0;
58
57
 
59
58
  for (let i = 0, n = file.statements.length; i < n; i++) {
60
59
  let stmt = file.statements[i];
@@ -68,10 +67,10 @@ function applyPrepend(code: string, file: ts.SourceFile, prepend: string[]): str
68
67
  }
69
68
 
70
69
  if (position === 0) {
71
- return text + code;
70
+ return prepend.join('\n') + code;
72
71
  }
73
72
 
74
- return code.slice(0, position) + '\n' + text + code.slice(position);
73
+ return code.slice(0, position) + prepend.join('\n') + code.slice(position);
75
74
  }
76
75
 
77
76
  function hasPattern(code: string, patterns: string[]): boolean {
@@ -85,16 +84,13 @@ function hasPattern(code: string, patterns: string[]): boolean {
85
84
  }
86
85
 
87
86
  function modify(code: string, file: ts.SourceFile, pkg: string, options: ModifyOptions): string {
88
- let { namespace } = options;
89
-
90
- // Fast path: nothing to change
91
87
  if (!options.add && !options.namespace && !options.remove) {
92
88
  return code;
93
89
  }
94
90
 
95
- let add = options.add ? new Set(options.add) : null,
96
- found = imports.find(file, pkg),
97
- remove = options.remove ? new Set(options.remove) : null;
91
+ let { namespace } = options,
92
+ add = options.add ? new Set(options.add) : null,
93
+ found = imports.find(file, pkg);
98
94
 
99
95
  if (found.length === 0) {
100
96
  let statements: string[] = [];
@@ -114,8 +110,9 @@ function modify(code: string, file: ts.SourceFile, pkg: string, options: ModifyO
114
110
  return statements.join('\n') + '\n' + code;
115
111
  }
116
112
 
117
- // Collect all non-removed specifiers from existing imports
118
- let specifiers = new Set<string>();
113
+ let remove = options.remove ? new Set(options.remove) : null,
114
+ // Collect all non-removed specifiers from existing imports
115
+ specifiers = new Set<string>();
119
116
 
120
117
  for (let i = 0, n = found.length; i < n; i++) {
121
118
  for (let [name, alias] of found[i].specifiers) {