Skip to content

Commit

Permalink
🐛Remove string.trimStart() from expander (ampproject#23439)
Browse files Browse the repository at this point in the history
* use new trimStart

* oops
  • Loading branch information
calebcordry authored and RINDO committed Jul 24, 2019
1 parent c35f640 commit 64e9ce1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/service/url-expander/expander.js
Expand Up @@ -16,6 +16,7 @@

import {hasOwn} from '../../utils/object';
import {rethrowAsync, user, userAssert} from '../../log';
import {trimStart} from '../../string';
import {tryResolve} from '../../utils/promise';

/** @private @const {string} */
Expand Down Expand Up @@ -150,7 +151,7 @@ export class Expander {
// Collect any chars that may be prefixing the macro, if we are in
// a nested context trim the args.
if (builder.trim().length) {
results.push(numOfPendingCalls ? builder.trimStart() : builder);
results.push(numOfPendingCalls ? trimStart(builder) : builder);
}

// If we know we are at the start of a macro, we figure out how to
Expand Down
13 changes: 13 additions & 0 deletions src/string.js
Expand Up @@ -158,3 +158,16 @@ export function trimEnd(str) {

return ('_' + str).trim().slice(1);
}

/**
* Trims any leading whitespace from a string.
* @param {string} str A string to trim.
* @return {string} The string, with leading whitespace removed.
*/
export function trimStart(str) {
if (str.trimStart) {
return str.trimStart();
}

return (str + '_').trim().slice(0, -1);
}

0 comments on commit 64e9ce1

Please sign in to comment.