mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
Merge branch 'main' into pr/kortin99/222319
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -118,7 +118,7 @@ variable ::= '$' var | '${' var }'
|
|||||||
| '${' var transform '}'
|
| '${' var transform '}'
|
||||||
transform ::= '/' regex '/' (format | text)+ '/' options
|
transform ::= '/' regex '/' (format | text)+ '/' options
|
||||||
format ::= '$' int | '${' int '}'
|
format ::= '$' int | '${' int '}'
|
||||||
| '${' int ':' '/upcase' | '/downcase' | '/capitalize' | '/camelcase' | '/pascalcase' | '/kebabcase' '}'
|
| '${' int ':' '/upcase' | '/downcase' | '/capitalize' | '/camelcase' | '/pascalcase' | '/kebabcase' | '/snakecase' '}'
|
||||||
| '${' int ':+' if '}'
|
| '${' int ':+' if '}'
|
||||||
| '${' int ':?' if ':' else '}'
|
| '${' int ':?' if ':' else '}'
|
||||||
| '${' int ':-' else '}' | '${' int ':' else '}'
|
| '${' int ':-' else '}' | '${' int ':' else '}'
|
||||||
|
|||||||
@@ -389,6 +389,8 @@ export class FormatString extends Marker {
|
|||||||
return !value ? '' : this._toCamelCase(value);
|
return !value ? '' : this._toCamelCase(value);
|
||||||
} else if (this.shorthandName === 'kebabcase') {
|
} else if (this.shorthandName === 'kebabcase') {
|
||||||
return !value ? '' : this._toKebabCase(value);
|
return !value ? '' : this._toKebabCase(value);
|
||||||
|
} else if (this.shorthandName === 'snakecase') {
|
||||||
|
return !value ? '' : this._toSnakeCase(value);
|
||||||
} else if (Boolean(value) && typeof this.ifValue === 'string') {
|
} else if (Boolean(value) && typeof this.ifValue === 'string') {
|
||||||
return this.ifValue;
|
return this.ifValue;
|
||||||
} else if (!Boolean(value) && typeof this.elseValue === 'string') {
|
} else if (!Boolean(value) && typeof this.elseValue === 'string') {
|
||||||
@@ -409,12 +411,18 @@ export class FormatString extends Marker {
|
|||||||
.trim()
|
.trim()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/^_+|_+$/g, '')
|
.replace(/^_+|_+$/g, '')
|
||||||
.replace(/[\s_]+/g, '-')
|
.replace(/[\s_]+/g, '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
const match2 = value
|
||||||
.trim()
|
.trim()
|
||||||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g);
|
||||||
|
|
||||||
|
if (!match2) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return match2
|
||||||
.map(x => x.toLowerCase())
|
.map(x => x.toLowerCase())
|
||||||
.join('-');
|
.join('-');
|
||||||
}
|
}
|
||||||
@@ -444,6 +452,12 @@ export class FormatString extends Marker {
|
|||||||
.join('');
|
.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _toSnakeCase(value: string): string {
|
||||||
|
return value.replace(/([a-z])([A-Z])/g, '$1_$2')
|
||||||
|
.replace(/[\s\-]+/g, '_')
|
||||||
|
.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
toTextmateString(): string {
|
toTextmateString(): string {
|
||||||
let value = '${';
|
let value = '${';
|
||||||
value += this.index;
|
value += this.index;
|
||||||
|
|||||||
@@ -677,6 +677,11 @@ suite('SnippetParser', () => {
|
|||||||
assert.strictEqual(new FormatString(1, 'kebabcase').resolve('_justPascalCase'), 'just-pascal-case');
|
assert.strictEqual(new FormatString(1, 'kebabcase').resolve('_justPascalCase'), 'just-pascal-case');
|
||||||
assert.strictEqual(new FormatString(1, 'kebabcase').resolve('__UPCASE__'), 'upcase');
|
assert.strictEqual(new FormatString(1, 'kebabcase').resolve('__UPCASE__'), 'upcase');
|
||||||
assert.strictEqual(new FormatString(1, 'kebabcase').resolve('__BAR_FOO__'), 'bar-foo');
|
assert.strictEqual(new FormatString(1, 'kebabcase').resolve('__BAR_FOO__'), 'bar-foo');
|
||||||
|
assert.strictEqual(new FormatString(1, 'snakecase').resolve('bar-foo'), 'bar_foo');
|
||||||
|
assert.strictEqual(new FormatString(1, 'snakecase').resolve('bar-42-foo'), 'bar_42_foo');
|
||||||
|
assert.strictEqual(new FormatString(1, 'snakecase').resolve('snake_AndPascalCase'), 'snake_and_pascal_case');
|
||||||
|
assert.strictEqual(new FormatString(1, 'snakecase').resolve('kebab-AndPascalCase'), 'kebab_and_pascal_case');
|
||||||
|
assert.strictEqual(new FormatString(1, 'snakecase').resolve('_justPascalCase'), '_just_pascal_case');
|
||||||
assert.strictEqual(new FormatString(1, 'notKnown').resolve('input'), 'input');
|
assert.strictEqual(new FormatString(1, 'notKnown').resolve('input'), 'input');
|
||||||
|
|
||||||
// if
|
// if
|
||||||
|
|||||||
Reference in New Issue
Block a user