?
u
/
This is the spec text of the String Dedent proposal in ECMAScript. String dedenting removes leading indentation from each line of a multiline string.
The String.dedent
function may be called with either a template array and a variable number of substitutions, or it may be called with a function which itself takes a template array and a variable number of substitutions.
When called with a template and a variable number of substitutions, a string is returned which has common leading indentation removed from all lines with non-whitespace.
When called with a function, a closure is returned which wraps the function. When the closure is called with a template and variable number of substitutions, the common leading indentation of the template is removed and the result of calling the function with this new dedented template and substitutions is returned.
Common leading indentation is defined as the longest sequence of whitespace characters that match exactly on every line that contains non-whitespace. Empty lines and lines which contain only whitespace do not affect common leading indentation.
When removing the common leading indentation, lines which contain only whitespace will have all whitespace removed.
The dedent
function is intended for use as a tag function of a Tagged Template (
The abstract operation DedentTemplateStringsArray takes argument template (an Object) and returns either a
The abstract operation DedentStringsArray takes argument template (an
The abstract operation CookStrings takes argument raw (a
The following grammar is used by
The abstract operation SplitTemplateIntoBlockLines takes arguments template (an
The abstract operation EmptyWhiteSpaceLines takes argument blocks (a
The abstract operation RemoveOpeningAndClosingLines takes arguments blocks (a
The abstract operation DetermineCommonLeadingIndentation takes argument blocks (a
The abstract operation LeadingWhiteSpaceSubstring takes argument str (a String) and returns a String. It performs the following steps when called:
When determining whether a Unicode code point is in Unicode general category “Space_Separator” (“Zs”), code unit sequences are interpreted as UTF-16 encoded code point sequences as specified in
The abstract operation IsAllWhiteSpace takes argument str (a String) and returns a Boolean. It performs the following steps when called:
The abstract operation LongestMatchingLeadingSubstring takes arguments a (a String) and b (a String) and returns a String. It performs the following steps when called:
The abstract operation CookTemplateStringsArray takes arguments template (an
This abstract operation merges the behaviour of String.raw
with the String.cooked proposal.
It performs the following steps when called:
Before it is evaluated, all ECMAScript code must be associated with a realm. Conceptually, a
A
Field Name | Value | Meaning |
---|---|---|
[[Intrinsics]] |
a |
The intrinsic values used by code associated with this |
[[GlobalObject]] |
an Object or |
The |
[[GlobalEnv]] |
a |
The global environment for this |
[[TemplateMap]] |
a |
Template objects are canonicalized separately for each Once a |
[[HostDefined]] |
anything (default value is |
Field reserved for use by |
[[DedentMap]] |
a |
The [[DedentMap]] ensures template tag functions wrapped with String.dedent see consistent object identity for a given input template. The [[Raw]] key weakly holds the value of a template object's raw property. The associated [[Dedented]] value is the result of performing dedenting on that raw value.
|
The abstract operation CreateRealm takes no arguments and returns a
At any time, if a set of objects S is not
Together with the definition of liveness, this clause prescribes legal optimizations that an implementation may apply regarding
It is possible to access an object without observing its identity. Optimizations such as dead variable elimination and scalar replacement on properties of non-escaping objects whose identity is not observed are allowed. These optimizations are thus allowed to observably empty
On the other hand, if an object's identity is observable, and that object is in the [[WeakRefTarget]] internal slot of a
Because calling
Implementations are not obligated to empty
If an implementation chooses a non-
© 2023 Justin Ridgewell
All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.