提交 91f26f80 编写于 作者: J Johannes Rieken

debt - refactor URI.withXYZ methods, #6678

上级 213699e0
......@@ -132,37 +132,17 @@ export default class URI {
// ---- modify to new -------------------------
public with(scheme: string, authority: string, path: string, query: string, fragment: string): URI {
public with(change: { scheme?: string; authority?: string; path?: string; query?: string; fragment?: string }): URI {
var ret = new URI();
ret._scheme = scheme || this.scheme;
ret._authority = authority || this.authority;
ret._path = path || this.path;
ret._query = query || this.query;
ret._fragment = fragment || this.fragment;
ret._scheme = change.scheme || this.scheme;
ret._authority = change.authority || this.authority;
ret._path = change.path || this.path;
ret._query = change.query || this.query;
ret._fragment = change.fragment || this.fragment;
URI._validate(ret);
return ret;
}
public withScheme(value: string): URI {
return this.with(value, undefined, undefined, undefined, undefined);
}
public withAuthority(value: string): URI {
return this.with(undefined, value, undefined, undefined, undefined);
}
public withPath(value: string): URI {
return this.with(undefined, undefined, value, undefined, undefined);
}
public withQuery(value: string): URI {
return this.with(undefined, undefined, undefined, value, undefined);
}
public withFragment(value: string): URI {
return this.with(undefined, undefined, undefined, undefined, value);
}
// ---- parse & validate ------------------------
public static parse(value: string): URI {
......@@ -232,7 +212,7 @@ export default class URI {
}
public static create(scheme?: string, authority?: string, path?: string, query?: string, fragment?: string): URI {
return new URI().with(scheme, authority, path, query, fragment);
return new URI().with({ scheme, authority, path, query, fragment });
}
private static _validate(ret: URI): void {
......
......@@ -45,7 +45,7 @@ suite('URI', () => {
test('http#toString, encode=FALSE', () => {
assert.equal(URI.create('http', 'a-test-site.com', '/', 'test=true').toString(true), 'http://a-test-site.com/?test=true');
assert.equal(URI.create('http', 'a-test-site.com', '/', '', 'test=true').toString(true), 'http://a-test-site.com/#test=true');
assert.equal(URI.create().withScheme('http').withPath('/api/files/test.me').withQuery('t=1234').toString(true), 'http:/api/files/test.me?t=1234');
assert.equal(URI.create().with({ scheme: 'http', path: '/api/files/test.me', query: 't=1234' }).toString(true), 'http:/api/files/test.me?t=1234');
var value = URI.parse('file://shares/pröjects/c%23/#l12');
assert.equal(value.authority, 'shares');
......@@ -63,12 +63,12 @@ suite('URI', () => {
});
test('with', () => {
assert.equal(URI.create().withScheme('http').withPath('/api/files/test.me').withQuery('t=1234').toString(), 'http:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with('http', '', '/api/files/test.me', 't=1234', '').toString(), 'http:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with('https', '', '/api/files/test.me', 't=1234', '').toString(), 'https:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with('HTTP', '', '/api/files/test.me', 't=1234', '').toString(), 'HTTP:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with('HTTPS', '', '/api/files/test.me', 't=1234', '').toString(), 'HTTPS:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with('boo', '', '/api/files/test.me', 't=1234', '').toString(), 'boo:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with({ scheme: 'http', path: '/api/files/test.me', query: 't=1234' }).toString(), 'http:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with({ scheme: 'http', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'http:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with({ scheme: 'https', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'https:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with({ scheme: 'HTTP', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'HTTP:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with({ scheme: 'HTTPS', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'HTTPS:/api/files/test.me?t%3D1234');
assert.equal(URI.create().with({ scheme: 'boo', authority: '', path: '/api/files/test.me', query: 't=1234', fragment: '' }).toString(), 'boo:/api/files/test.me?t%3D1234');
});
test('parse', () => {
......
......@@ -376,7 +376,7 @@ export class MirrorModel extends AbstractMirrorModel implements editorCommon.IMi
this._embeddedModels[newNestedModeId].setIncludedRanges(newModesRanges[newNestedModeId].ranges);
} else {
// TODO@Alex: implement derived resources (embedded mirror models) better
var embeddedModelUrl = this.uri.withFragment(this.uri.fragment + 'URL_MARSHAL_REMOVE' + newNestedModeId);
var embeddedModelUrl = this.uri.with({ fragment: this.uri.fragment + 'URL_MARSHAL_REMOVE' + newNestedModeId });
this._embeddedModels[newNestedModeId] = new MirrorModelEmbedded(this, newModesRanges[newNestedModeId].ranges, newModesRanges[newNestedModeId].mode, embeddedModelUrl);
this._resourceService.insert(this._embeddedModels[newNestedModeId].uri, this._embeddedModels[newNestedModeId]);
}
......
......@@ -548,7 +548,7 @@ export class HTMLWorker {
alternativeResultPath = paths.join(modelPath, tokenContent);
alternativeResultPath = alternativeResultPath.replace(/^(\/\.\.)+/, '');
}
let potentialResult = modelAbsoluteUri.withPath(alternativeResultPath).toString();
let potentialResult = modelAbsoluteUri.with({ path: alternativeResultPath }).toString();
let rootAbsoluteUrlStr = (rootAbsoluteUri ? rootAbsoluteUri.toString() : null);
if (rootAbsoluteUrlStr && strings.startsWith(modelAbsoluteUri.toString(), rootAbsoluteUrlStr)) {
......
......@@ -166,7 +166,7 @@ class DirtyDiffModelDecorator {
this.gitService = gitService;
this.model = model;
this._originalContentsURI = model.uri.withScheme(DirtyDiffModelDecorator.GIT_ORIGINAL_SCHEME);
this._originalContentsURI = model.uri.with({ scheme: DirtyDiffModelDecorator.GIT_ORIGINAL_SCHEME });
this.path = path;
this.decorations = [];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册