summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/compiler/bundler.ts9
-rw-r--r--cli/js/compiler/util.ts22
2 files changed, 8 insertions, 23 deletions
diff --git a/cli/js/compiler/bundler.ts b/cli/js/compiler/bundler.ts
index c9578fe20..3f05a3be3 100644
--- a/cli/js/compiler/bundler.ts
+++ b/cli/js/compiler/bundler.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { SYSTEM_LOADER } from "./bootstrap.ts";
-import { commonPath, normalizeString, CHAR_FORWARD_SLASH } from "./util.ts";
+import { commonPath, normalizeString } from "./util.ts";
import { assert } from "../util.ts";
let rootExports: string[] | undefined;
@@ -10,12 +10,7 @@ function normalizeUrl(rootName: string): string {
const match = /^(\S+:\/{2,3})(.+)$/.exec(rootName);
if (match) {
const [, protocol, path] = match;
- return `${protocol}${normalizeString(
- path,
- false,
- "/",
- (code) => code === CHAR_FORWARD_SLASH
- )}`;
+ return `${protocol}${normalizeString(path)}`;
} else {
return rootName;
}
diff --git a/cli/js/compiler/util.ts b/cli/js/compiler/util.ts
index d461fcbbb..35ce2e837 100644
--- a/cli/js/compiler/util.ts
+++ b/cli/js/compiler/util.ts
@@ -299,12 +299,7 @@ export function processConfigureResponse(
export const CHAR_DOT = 46; /* . */
export const CHAR_FORWARD_SLASH = 47; /* / */
-export function normalizeString(
- path: string,
- allowAboveRoot: boolean,
- separator: string,
- isPathSeparator: (code: number) => boolean
-): string {
+export function normalizeString(path: string): string {
let res = "";
let lastSegmentLength = 0;
let lastSlash = -1;
@@ -312,10 +307,10 @@ export function normalizeString(
let code: number;
for (let i = 0, len = path.length; i <= len; ++i) {
if (i < len) code = path.charCodeAt(i);
- else if (isPathSeparator(code!)) break;
+ else if (code! === CHAR_FORWARD_SLASH) break;
else code = CHAR_FORWARD_SLASH;
- if (isPathSeparator(code)) {
+ if (code === CHAR_FORWARD_SLASH) {
if (lastSlash === i - 1 || dots === 1) {
// NOOP
} else if (lastSlash !== i - 1 && dots === 2) {
@@ -326,13 +321,13 @@ export function normalizeString(
res.charCodeAt(res.length - 2) !== CHAR_DOT
) {
if (res.length > 2) {
- const lastSlashIndex = res.lastIndexOf(separator);
+ const lastSlashIndex = res.lastIndexOf("/");
if (lastSlashIndex === -1) {
res = "";
lastSegmentLength = 0;
} else {
res = res.slice(0, lastSlashIndex);
- lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
}
lastSlash = i;
dots = 0;
@@ -345,13 +340,8 @@ export function normalizeString(
continue;
}
}
- if (allowAboveRoot) {
- if (res.length > 0) res += `${separator}..`;
- else res = "..";
- lastSegmentLength = 2;
- }
} else {
- if (res.length > 0) res += separator + path.slice(lastSlash + 1, i);
+ if (res.length > 0) res += "/" + path.slice(lastSlash + 1, i);
else res = path.slice(lastSlash + 1, i);
lastSegmentLength = i - lastSlash - 1;
}