diff --git a/dist/css/print.css b/dist/css/print.css index 9470571f3e0..32bf0c863a1 100644 --- a/dist/css/print.css +++ b/dist/css/print.css @@ -184,6 +184,7 @@ .swagger-section .swagger-ui-wrap { line-height: 1; font-family: "Droid Sans", sans-serif; + min-width: 760px; max-width: 960px; margin-left: auto; margin-right: auto; @@ -1180,18 +1181,122 @@ } .swagger-section .oauth_submit { text-align: center; + display: inline-block; +} +.swagger-section .authorize-wrapper { + margin: 15px 0 10px; +} +.swagger-section .authorize-wrapper_operation { + float: right; +} +.swagger-section .authorize__btn:hover { + text-decoration: underline; + cursor: pointer; +} +.swagger-section .authorize__btn_operation:hover .authorize-scopes { + display: block; +} +.swagger-section .authorize-scopes { + position: absolute; + margin-top: 20px; + background: #FFF; + border: 1px solid #ccc; + border-radius: 5px; + display: none; + font-size: 13px; + max-width: 300px; + line-height: 30px; + color: black; + padding: 5px; +} +.swagger-section .authorize-scopes .authorize__scope { + text-decoration: none; +} +.swagger-section .authorize__btn_operation { + height: 18px; + vertical-align: middle; + display: inline-block; + background: url(../images/explorer_icons.png) no-repeat; +} +.swagger-section .authorize__btn_operation_login { + background-position: 0 0; + width: 18px; + margin-top: -6px; + margin-left: 4px; +} +.swagger-section .authorize__btn_operation_logout { + background-position: -30px 0; + width: 18px; + margin-top: -6px; + margin-left: 4px; +} +.swagger-section #auth_container { + color: #fff; + display: inline-block; + border: none; + padding: 5px; + width: 87px; + height: 13px; +} +.swagger-section #auth_container .authorize__btn { + color: #fff; +} +.swagger-section .auth_container { + padding: 0 0 10px; + margin-bottom: 5px; + border-bottom: solid 1px #CCC; + font-size: 0.9em; +} +.swagger-section .auth_container .auth__title { + color: #547f00; + font-size: 1.2em; +} +.swagger-section .auth_container .basic_auth__label { + display: inline-block; + width: 60px; +} +.swagger-section .auth_container .auth__description { + color: #999999; + margin-bottom: 5px; +} +.swagger-section .auth_container .auth__button { + margin-top: 10px; + height: 30px; +} +.swagger-section .auth_container .key_auth__field { + margin: 5px 0; +} +.swagger-section .auth_container .key_auth__label { + display: inline-block; + width: 60px; } .swagger-section .api-popup-dialog { - z-index: 10000; position: absolute; + display: none; +} +.swagger-section .api-popup-dialog-wrapper { + z-index: 1000; width: 500px; background: #FFF; padding: 20px; border: 1px solid #ccc; border-radius: 5px; - display: none; font-size: 13px; color: #777; + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +} +.swagger-section .api-popup-dialog-shadow { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + opacity: 0.2; + background-color: gray; + z-index: 900; } .swagger-section .api-popup-dialog .api-popup-title { font-size: 24px; @@ -1205,6 +1310,10 @@ padding-left: 5px; padding-bottom: 5px; } +.swagger-section .api-popup-dialog .api-popup-content { + max-height: 500px; + overflow-y: auto; +} .swagger-section .api-popup-dialog .api-popup-authbtn { height: 30px; } diff --git a/dist/css/screen.css b/dist/css/screen.css index 9fbd283bfac..90a93a2d9e2 100644 --- a/dist/css/screen.css +++ b/dist/css/screen.css @@ -184,6 +184,7 @@ .swagger-section .swagger-ui-wrap { line-height: 1; font-family: "Droid Sans", sans-serif; + min-width: 760px; max-width: 960px; margin-left: auto; margin-right: auto; @@ -1180,18 +1181,122 @@ } .swagger-section .oauth_submit { text-align: center; + display: inline-block; +} +.swagger-section .authorize-wrapper { + margin: 15px 0 10px; +} +.swagger-section .authorize-wrapper_operation { + float: right; +} +.swagger-section .authorize__btn:hover { + text-decoration: underline; + cursor: pointer; +} +.swagger-section .authorize__btn_operation:hover .authorize-scopes { + display: block; +} +.swagger-section .authorize-scopes { + position: absolute; + margin-top: 20px; + background: #FFF; + border: 1px solid #ccc; + border-radius: 5px; + display: none; + font-size: 13px; + max-width: 300px; + line-height: 30px; + color: black; + padding: 5px; +} +.swagger-section .authorize-scopes .authorize__scope { + text-decoration: none; +} +.swagger-section .authorize__btn_operation { + height: 18px; + vertical-align: middle; + display: inline-block; + background: url(../images/explorer_icons.png) no-repeat; +} +.swagger-section .authorize__btn_operation_login { + background-position: 0 0; + width: 18px; + margin-top: -6px; + margin-left: 4px; +} +.swagger-section .authorize__btn_operation_logout { + background-position: -30px 0; + width: 18px; + margin-top: -6px; + margin-left: 4px; +} +.swagger-section #auth_container { + color: #fff; + display: inline-block; + border: none; + padding: 5px; + width: 87px; + height: 13px; +} +.swagger-section #auth_container .authorize__btn { + color: #fff; +} +.swagger-section .auth_container { + padding: 0 0 10px; + margin-bottom: 5px; + border-bottom: solid 1px #CCC; + font-size: 0.9em; +} +.swagger-section .auth_container .auth__title { + color: #547f00; + font-size: 1.2em; +} +.swagger-section .auth_container .basic_auth__label { + display: inline-block; + width: 60px; +} +.swagger-section .auth_container .auth__description { + color: #999999; + margin-bottom: 5px; +} +.swagger-section .auth_container .auth__button { + margin-top: 10px; + height: 30px; +} +.swagger-section .auth_container .key_auth__field { + margin: 5px 0; +} +.swagger-section .auth_container .key_auth__label { + display: inline-block; + width: 60px; } .swagger-section .api-popup-dialog { - z-index: 10000; position: absolute; + display: none; +} +.swagger-section .api-popup-dialog-wrapper { + z-index: 1000; width: 500px; background: #FFF; padding: 20px; border: 1px solid #ccc; border-radius: 5px; - display: none; font-size: 13px; color: #777; + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +} +.swagger-section .api-popup-dialog-shadow { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + opacity: 0.2; + background-color: gray; + z-index: 900; } .swagger-section .api-popup-dialog .api-popup-title { font-size: 24px; @@ -1205,6 +1310,10 @@ padding-left: 5px; padding-bottom: 5px; } +.swagger-section .api-popup-dialog .api-popup-content { + max-height: 500px; + overflow-y: auto; +} .swagger-section .api-popup-dialog .api-popup-authbtn { height: 30px; } @@ -1297,7 +1406,9 @@ } .swagger-section #header { background-color: #89bf04; - padding: 14px; + padding: 9px 14px 19px 14px; + height: 23px; + min-width: 775px; } .swagger-section #input_baseUrl { width: 400px; @@ -1308,9 +1419,8 @@ float: right; } .swagger-section #api_selector .input { - display: block; + display: inline-block; clear: none; - float: left; margin: 0 10px 0 0; } .swagger-section #api_selector input { @@ -1321,7 +1431,8 @@ .swagger-section #input_apiKey { width: 200px; } -.swagger-section #explore { +.swagger-section #explore, +.swagger-section #auth_container .authorize__btn { display: block; text-decoration: none; font-weight: bold; @@ -1336,17 +1447,25 @@ -khtml-border-radius: 4px; border-radius: 4px; } -.swagger-section #explore:hover { +.swagger-section #explore:hover, +.swagger-section #auth_container .authorize__btn:hover { background-color: #547f00; } .swagger-section #header #logo { font-size: 1.5em; font-weight: bold; text-decoration: none; - background: transparent url(../images/logo_small.png) no-repeat left center; - padding: 20px 0 20px 40px; color: white; } +.swagger-section #header #logo .logo__img { + display: block; + float: left; + margin-top: 2px; +} +.swagger-section #header #logo .logo__title { + display: inline-block; + padding: 5px 0 0 10px; +} .swagger-section #content_message { margin: 10px 15px; font-style: italic; @@ -1363,3 +1482,7 @@ .swagger-section .swagger-expand:before { content: "+"; } +.swagger-section .error { + outline-color: #cc0000; + background-color: #f2dede; +} diff --git a/dist/index.html b/dist/index.html index d95471a1247..4bd82d5c4e8 100644 --- a/dist/index.html +++ b/dist/index.html @@ -67,7 +67,7 @@ window.SwaggerTranslator.translate(); } - addApiKeyAuthorization(); +// addApiKeyAuthorization(); }, onFailure: function(data) { log("Unable to Load SwaggerUI"); @@ -79,16 +79,16 @@ showRequestHeaders: false }); - function addApiKeyAuthorization(){ - var key = encodeURIComponent($('#input_apiKey')[0].value); - if(key && key.trim() != "") { - var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query"); - window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth); - log("added key " + key); - } - } - - $('#input_apiKey').change(addApiKeyAuthorization); +// function addApiKeyAuthorization(){ +// var key = encodeURIComponent($('#input_apiKey')[0].value); +// if(key && key.trim() != "") { +// var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query"); +// window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth); +// log("added key " + key); +// } +// } +// +// $('#input_apiKey').change(addApiKeyAuthorization); // if you have an apiKey you would like to pre-populate on the page for demonstration purposes... /* @@ -110,11 +110,11 @@
diff --git a/dist/lib/swagger-oauth.js b/dist/lib/swagger-oauth.js index 576fcd33bf9..2bb6be1143c 100644 --- a/dist/lib/swagger-oauth.js +++ b/dist/lib/swagger-oauth.js @@ -331,7 +331,8 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) { } } }); - window.swaggerUi.api.clientAuthorizations.add(OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header')); + window.swaggerUi.api.clientAuthorizations.add(window.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header')); + window.swaggerUi.load(); } } } diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js index 2baeb47e95a..7e97557b562 100644 --- a/dist/swagger-ui.js +++ b/dist/swagger-ui.js @@ -6,15 +6,90 @@ */ (function(){this["Handlebars"] = this["Handlebars"] || {}; this["Handlebars"]["templates"] = this["Handlebars"]["templates"] || {}; -this["Handlebars"]["templates"]["apikey_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { +this["Handlebars"]["templates"]["apikey_auth"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return "\n" + + escapeExpression(((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper))) + + "
\nScopes are used to grant an application different levels of access to data on behalf of the end user. Each API may declare one or more scopes.\n Learn how to use\n
\n" + + escapeExpression(((helper = (helper = helpers.appName || (depth0 != null ? depth0.appName : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"appName","hash":{},"data":data}) : helper))) + + " API requires the following scopes. Select which ones you want to grant to Swagger UI.
\nAuthorization URL: " + + escapeExpression(((helper = (helper = helpers.authorizationUrl || (depth0 != null ? depth0.authorizationUrl : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"authorizationUrl","hash":{},"data":data}) : helper))) + + "
\nflow: " + + escapeExpression(((helper = (helper = helpers.flow || (depth0 != null ? depth0.flow : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"flow","hash":{},"data":data}) : helper))) + + "
\n\n
Header | \nDescription | \nType | \nOther | \n
---|
Parameter | \nValue | \nDescription | \nParameter Type | \nData Type | \n
---|
HTTP Status Code | \nReason | \nResponse Model | \nHeaders | \n
---|
expect(value)
- * @since 2.0
- */
- function expectCommaSeparator() {
- var token;
-
- if (extra.errors) {
- token = lookahead;
- if (token.type === Token.Punctuator && token.value === ',') {
- lex();
- } else if (token.type === Token.Punctuator && token.value === ';') {
- lex();
- tolerateUnexpectedToken(token);
- } else {
- tolerateUnexpectedToken(token, Messages.UnexpectedToken);
- }
- } else {
- expect(',');
- }
- }
+ if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
+ throwWarning(state, 'deficient indentation');
+ }
- // Expect the next token to match the specified keyword.
- // If not, an exception will be thrown.
+ return lineBreaks;
+}
- function expectKeyword(keyword) {
- var token = lex();
- if (token.type !== Token.Keyword || token.value !== keyword) {
- throwUnexpectedToken(token);
- }
- }
+function testDocumentSeparator(state) {
+ var _position = state.position,
+ ch;
- // Return true if the next token matches the specified punctuator.
+ ch = state.input.charCodeAt(_position);
- function match(value) {
- return lookahead.type === Token.Punctuator && lookahead.value === value;
- }
+ // Condition state.position === state.lineStart is tested
+ // in parent on each call, for efficiency. No needs to test here again.
+ if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
+ ch === state.input.charCodeAt(_position + 1) &&
+ ch === state.input.charCodeAt(_position + 2)) {
- // Return true if the next token matches the specified keyword
+ _position += 3;
+
+ ch = state.input.charCodeAt(_position);
- function matchKeyword(keyword) {
- return lookahead.type === Token.Keyword && lookahead.value === keyword;
+ if (ch === 0 || is_WS_OR_EOL(ch)) {
+ return true;
}
+ }
- // Return true if the next token matches the specified contextual keyword
- // (where an identifier is sometimes a keyword depending on the context)
+ return false;
+}
- function matchContextualKeyword(keyword) {
- return lookahead.type === Token.Identifier && lookahead.value === keyword;
- }
+function writeFoldedLines(state, count) {
+ if (count === 1) {
+ state.result += ' ';
+ } else if (count > 1) {
+ state.result += common.repeat('\n', count - 1);
+ }
+}
- // Return true if the next token is an assignment operator
- function matchAssign() {
- var op;
+function readPlainScalar(state, nodeIndent, withinFlowCollection) {
+ var preceding,
+ following,
+ captureStart,
+ captureEnd,
+ hasPendingContent,
+ _line,
+ _lineStart,
+ _lineIndent,
+ _kind = state.kind,
+ _result = state.result,
+ ch;
- if (lookahead.type !== Token.Punctuator) {
- return false;
- }
- op = lookahead.value;
- return op === '=' ||
- op === '*=' ||
- op === '/=' ||
- op === '%=' ||
- op === '+=' ||
- op === '-=' ||
- op === '<<=' ||
- op === '>>=' ||
- op === '>>>=' ||
- op === '&=' ||
- op === '^=' ||
- op === '|=';
- }
-
- function consumeSemicolon() {
- // Catch the very common case first: immediately a semicolon (U+003B).
- if (source.charCodeAt(startIndex) === 0x3B || match(';')) {
- lex();
- return;
- }
+ ch = state.input.charCodeAt(state.position);
- if (hasLineTerminator) {
- return;
- }
+ if (is_WS_OR_EOL(ch) ||
+ is_FLOW_INDICATOR(ch) ||
+ ch === 0x23/* # */ ||
+ ch === 0x26/* & */ ||
+ ch === 0x2A/* * */ ||
+ ch === 0x21/* ! */ ||
+ ch === 0x7C/* | */ ||
+ ch === 0x3E/* > */ ||
+ ch === 0x27/* ' */ ||
+ ch === 0x22/* " */ ||
+ ch === 0x25/* % */ ||
+ ch === 0x40/* @ */ ||
+ ch === 0x60/* ` */) {
+ return false;
+ }
- // FIXME(ikarienator): this is seemingly an issue in the previous location info convention.
- lastIndex = startIndex;
- lastLineNumber = startLineNumber;
- lastLineStart = startLineStart;
+ if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
+ following = state.input.charCodeAt(state.position + 1);
- if (lookahead.type !== Token.EOF && !match('}')) {
- throwUnexpectedToken(lookahead);
- }
+ if (is_WS_OR_EOL(following) ||
+ withinFlowCollection && is_FLOW_INDICATOR(following)) {
+ return false;
}
+ }
- // Cover grammar support.
- //
- // When an assignment expression position starts with an left parenthesis, the determination of the type
- // of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)
- // or the first comma. This situation also defers the determination of all the expressions nested in the pair.
- //
- // There are three productions that can be parsed in a parentheses pair that needs to be determined
- // after the outermost pair is closed. They are:
- //
- // 1. AssignmentExpression
- // 2. BindingElements
- // 3. AssignmentTargets
- //
- // In order to avoid exponential backtracking, we use two flags to denote if the production can be
- // binding element or assignment target.
- //
- // The three productions have the relationship:
- //
- // BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression
- //
- // with a single exception that CoverInitializedName when used directly in an Expression, generates
- // an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the
- // first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.
- //
- // isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not
- // effect the current flags. This means the production the parser parses is only used as an expression. Therefore
- // the CoverInitializedName check is conducted.
- //
- // inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates
- // the flags outside of the parser. This means the production the parser parses is used as a part of a potential
- // pattern. The CoverInitializedName check is deferred.
- function isolateCoverGrammar(parser) {
- var oldIsBindingElement = isBindingElement,
- oldIsAssignmentTarget = isAssignmentTarget,
- oldFirstCoverInitializedNameError = firstCoverInitializedNameError,
- result;
- isBindingElement = true;
- isAssignmentTarget = true;
- firstCoverInitializedNameError = null;
- result = parser();
- if (firstCoverInitializedNameError !== null) {
- throwUnexpectedToken(firstCoverInitializedNameError);
- }
- isBindingElement = oldIsBindingElement;
- isAssignmentTarget = oldIsAssignmentTarget;
- firstCoverInitializedNameError = oldFirstCoverInitializedNameError;
- return result;
- }
+ state.kind = 'scalar';
+ state.result = '';
+ captureStart = captureEnd = state.position;
+ hasPendingContent = false;
- function inheritCoverGrammar(parser) {
- var oldIsBindingElement = isBindingElement,
- oldIsAssignmentTarget = isAssignmentTarget,
- oldFirstCoverInitializedNameError = firstCoverInitializedNameError,
- result;
- isBindingElement = true;
- isAssignmentTarget = true;
- firstCoverInitializedNameError = null;
- result = parser();
- isBindingElement = isBindingElement && oldIsBindingElement;
- isAssignmentTarget = isAssignmentTarget && oldIsAssignmentTarget;
- firstCoverInitializedNameError = oldFirstCoverInitializedNameError || firstCoverInitializedNameError;
- return result;
- }
+ while (ch !== 0) {
+ if (ch === 0x3A/* : */) {
+ following = state.input.charCodeAt(state.position + 1);
- // ECMA-262 13.3.3 Destructuring Binding Patterns
+ if (is_WS_OR_EOL(following) ||
+ withinFlowCollection && is_FLOW_INDICATOR(following)) {
+ break;
+ }
- function parseArrayPattern(params, kind) {
- var node = new Node(), elements = [], rest, restNode;
- expect('[');
+ } else if (ch === 0x23/* # */) {
+ preceding = state.input.charCodeAt(state.position - 1);
- while (!match(']')) {
- if (match(',')) {
- lex();
- elements.push(null);
- } else {
- if (match('...')) {
- restNode = new Node();
- lex();
- params.push(lookahead);
- rest = parseVariableIdentifier(kind);
- elements.push(restNode.finishRestElement(rest));
- break;
- } else {
- elements.push(parsePatternWithDefault(params, kind));
- }
- if (!match(']')) {
- expect(',');
- }
- }
+ if (is_WS_OR_EOL(preceding)) {
+ break;
+ }
- }
+ } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
+ withinFlowCollection && is_FLOW_INDICATOR(ch)) {
+ break;
- expect(']');
+ } else if (is_EOL(ch)) {
+ _line = state.line;
+ _lineStart = state.lineStart;
+ _lineIndent = state.lineIndent;
+ skipSeparationSpace(state, false, -1);
- return node.finishArrayPattern(elements);
+ if (state.lineIndent >= nodeIndent) {
+ hasPendingContent = true;
+ ch = state.input.charCodeAt(state.position);
+ continue;
+ } else {
+ state.position = captureEnd;
+ state.line = _line;
+ state.lineStart = _lineStart;
+ state.lineIndent = _lineIndent;
+ break;
+ }
}
- function parsePropertyPattern(params, kind) {
- var node = new Node(), key, keyToken, computed = match('['), init;
- if (lookahead.type === Token.Identifier) {
- keyToken = lookahead;
- key = parseVariableIdentifier();
- if (match('=')) {
- params.push(keyToken);
- lex();
- init = parseAssignmentExpression();
+ if (hasPendingContent) {
+ captureSegment(state, captureStart, captureEnd, false);
+ writeFoldedLines(state, state.line - _line);
+ captureStart = captureEnd = state.position;
+ hasPendingContent = false;
+ }
- return node.finishProperty(
- 'init', key, false,
- new WrappingNode(keyToken).finishAssignmentPattern(key, init), false, false);
- } else if (!match(':')) {
- params.push(keyToken);
- return node.finishProperty('init', key, false, key, false, true);
- }
- } else {
- key = parseObjectPropertyKey();
- }
- expect(':');
- init = parsePatternWithDefault(params, kind);
- return node.finishProperty('init', key, computed, init, false, false);
+ if (!is_WHITE_SPACE(ch)) {
+ captureEnd = state.position + 1;
}
- function parseObjectPattern(params, kind) {
- var node = new Node(), properties = [];
+ ch = state.input.charCodeAt(++state.position);
+ }
- expect('{');
+ captureSegment(state, captureStart, captureEnd, false);
- while (!match('}')) {
- properties.push(parsePropertyPattern(params, kind));
- if (!match('}')) {
- expect(',');
- }
- }
+ if (state.result) {
+ return true;
+ }
- lex();
+ state.kind = _kind;
+ state.result = _result;
+ return false;
+}
- return node.finishObjectPattern(properties);
- }
+function readSingleQuotedScalar(state, nodeIndent) {
+ var ch,
+ captureStart, captureEnd;
- function parsePattern(params, kind) {
- if (match('[')) {
- return parseArrayPattern(params, kind);
- } else if (match('{')) {
- return parseObjectPattern(params, kind);
- } else if (matchKeyword('let')) {
- if (kind === 'const' || kind === 'let') {
- tolerateUnexpectedToken(lookahead, Messages.UnexpectedToken);
- }
- }
+ ch = state.input.charCodeAt(state.position);
- params.push(lookahead);
- return parseVariableIdentifier(kind);
- }
+ if (ch !== 0x27/* ' */) {
+ return false;
+ }
- function parsePatternWithDefault(params, kind) {
- var startToken = lookahead, pattern, previousAllowYield, right;
- pattern = parsePattern(params, kind);
- if (match('=')) {
- lex();
- previousAllowYield = state.allowYield;
- state.allowYield = true;
- right = isolateCoverGrammar(parseAssignmentExpression);
- state.allowYield = previousAllowYield;
- pattern = new WrappingNode(startToken).finishAssignmentPattern(pattern, right);
- }
- return pattern;
+ state.kind = 'scalar';
+ state.result = '';
+ state.position++;
+ captureStart = captureEnd = state.position;
+
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
+ if (ch === 0x27/* ' */) {
+ captureSegment(state, captureStart, state.position, true);
+ ch = state.input.charCodeAt(++state.position);
+
+ if (ch === 0x27/* ' */) {
+ captureStart = captureEnd = state.position;
+ state.position++;
+ } else {
+ return true;
+ }
+
+ } else if (is_EOL(ch)) {
+ captureSegment(state, captureStart, captureEnd, true);
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
+ captureStart = captureEnd = state.position;
+
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
+ throwError(state, 'unexpected end of the document within a single quoted scalar');
+
+ } else {
+ state.position++;
+ captureEnd = state.position;
}
+ }
- // ECMA-262 12.2.5 Array Initializer
+ throwError(state, 'unexpected end of the stream within a single quoted scalar');
+}
- function parseArrayInitializer() {
- var elements = [], node = new Node(), restSpread;
+function readDoubleQuotedScalar(state, nodeIndent) {
+ var captureStart,
+ captureEnd,
+ hexLength,
+ hexResult,
+ tmp,
+ ch;
- expect('[');
+ ch = state.input.charCodeAt(state.position);
- while (!match(']')) {
- if (match(',')) {
- lex();
- elements.push(null);
- } else if (match('...')) {
- restSpread = new Node();
- lex();
- restSpread.finishSpreadElement(inheritCoverGrammar(parseAssignmentExpression));
+ if (ch !== 0x22/* " */) {
+ return false;
+ }
- if (!match(']')) {
- isAssignmentTarget = isBindingElement = false;
- expect(',');
- }
- elements.push(restSpread);
- } else {
- elements.push(inheritCoverGrammar(parseAssignmentExpression));
+ state.kind = 'scalar';
+ state.result = '';
+ state.position++;
+ captureStart = captureEnd = state.position;
- if (!match(']')) {
- expect(',');
- }
- }
- }
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
+ if (ch === 0x22/* " */) {
+ captureSegment(state, captureStart, state.position, true);
+ state.position++;
+ return true;
- lex();
+ } else if (ch === 0x5C/* \ */) {
+ captureSegment(state, captureStart, state.position, true);
+ ch = state.input.charCodeAt(++state.position);
- return node.finishArrayExpression(elements);
- }
+ if (is_EOL(ch)) {
+ skipSeparationSpace(state, false, nodeIndent);
- // ECMA-262 12.2.6 Object Initializer
+ // TODO: rework to inline fn with no type cast?
+ } else if (ch < 256 && simpleEscapeCheck[ch]) {
+ state.result += simpleEscapeMap[ch];
+ state.position++;
- function parsePropertyFunction(node, paramInfo, isGenerator) {
- var previousStrict, body;
+ } else if ((tmp = escapedHexLen(ch)) > 0) {
+ hexLength = tmp;
+ hexResult = 0;
- isAssignmentTarget = isBindingElement = false;
+ for (; hexLength > 0; hexLength--) {
+ ch = state.input.charCodeAt(++state.position);
- previousStrict = strict;
- body = isolateCoverGrammar(parseFunctionSourceElements);
+ if ((tmp = fromHexCode(ch)) >= 0) {
+ hexResult = (hexResult << 4) + tmp;
- if (strict && paramInfo.firstRestricted) {
- tolerateUnexpectedToken(paramInfo.firstRestricted, paramInfo.message);
- }
- if (strict && paramInfo.stricted) {
- tolerateUnexpectedToken(paramInfo.stricted, paramInfo.message);
+ } else {
+ throwError(state, 'expected hexadecimal character');
+ }
}
- strict = previousStrict;
- return node.finishFunctionExpression(null, paramInfo.params, paramInfo.defaults, body, isGenerator);
- }
-
- function parsePropertyMethodFunction() {
- var params, method, node = new Node(),
- previousAllowYield = state.allowYield;
-
- state.allowYield = false;
- params = parseParams();
- state.allowYield = previousAllowYield;
+ state.result += charFromCodepoint(hexResult);
- state.allowYield = false;
- method = parsePropertyFunction(node, params, false);
- state.allowYield = previousAllowYield;
+ state.position++;
- return method;
- }
+ } else {
+ throwError(state, 'unknown escape sequence');
+ }
- function parseObjectPropertyKey() {
- var token, node = new Node(), expr;
+ captureStart = captureEnd = state.position;
- token = lex();
+ } else if (is_EOL(ch)) {
+ captureSegment(state, captureStart, captureEnd, true);
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
+ captureStart = captureEnd = state.position;
- // Note: This function is called only from parseObjectProperty(), where
- // EOF and Punctuator tokens are already filtered out.
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
+ throwError(state, 'unexpected end of the document within a double quoted scalar');
- switch (token.type) {
- case Token.StringLiteral:
- case Token.NumericLiteral:
- if (strict && token.octal) {
- tolerateUnexpectedToken(token, Messages.StrictOctalLiteral);
- }
- return node.finishLiteral(token);
- case Token.Identifier:
- case Token.BooleanLiteral:
- case Token.NullLiteral:
- case Token.Keyword:
- return node.finishIdentifier(token.value);
- case Token.Punctuator:
- if (token.value === '[') {
- expr = isolateCoverGrammar(parseAssignmentExpression);
- expect(']');
- return expr;
- }
- break;
- }
- throwUnexpectedToken(token);
+ } else {
+ state.position++;
+ captureEnd = state.position;
}
+ }
- function lookaheadPropertyName() {
- switch (lookahead.type) {
- case Token.Identifier:
- case Token.StringLiteral:
- case Token.BooleanLiteral:
- case Token.NullLiteral:
- case Token.NumericLiteral:
- case Token.Keyword:
- return true;
- case Token.Punctuator:
- return lookahead.value === '[';
- }
- return false;
- }
+ throwError(state, 'unexpected end of the stream within a double quoted scalar');
+}
- // This function is to try to parse a MethodDefinition as defined in 14.3. But in the case of object literals,
- // it might be called at a position where there is in fact a short hand identifier pattern or a data property.
- // This can only be determined after we consumed up to the left parentheses.
- //
- // In order to avoid back tracking, it returns `null` if the position is not a MethodDefinition and the caller
- // is responsible to visit other options.
- function tryParseMethodDefinition(token, key, computed, node) {
- var value, options, methodNode, params,
- previousAllowYield = state.allowYield;
-
- if (token.type === Token.Identifier) {
- // check for `get` and `set`;
-
- if (token.value === 'get' && lookaheadPropertyName()) {
- computed = match('[');
- key = parseObjectPropertyKey();
- methodNode = new Node();
- expect('(');
- expect(')');
-
- state.allowYield = false;
- value = parsePropertyFunction(methodNode, {
- params: [],
- defaults: [],
- stricted: null,
- firstRestricted: null,
- message: null
- }, false);
- state.allowYield = previousAllowYield;
-
- return node.finishProperty('get', key, computed, value, false, false);
- } else if (token.value === 'set' && lookaheadPropertyName()) {
- computed = match('[');
- key = parseObjectPropertyKey();
- methodNode = new Node();
- expect('(');
-
- options = {
- params: [],
- defaultCount: 0,
- defaults: [],
- firstRestricted: null,
- paramSet: {}
- };
- if (match(')')) {
- tolerateUnexpectedToken(lookahead);
- } else {
- state.allowYield = false;
- parseParam(options);
- state.allowYield = previousAllowYield;
- if (options.defaultCount === 0) {
- options.defaults = [];
- }
- }
- expect(')');
+function readFlowCollection(state, nodeIndent) {
+ var readNext = true,
+ _line,
+ _tag = state.tag,
+ _result,
+ _anchor = state.anchor,
+ following,
+ terminator,
+ isPair,
+ isExplicitPair,
+ isMapping,
+ overridableKeys = {},
+ keyNode,
+ keyTag,
+ valueNode,
+ ch;
- state.allowYield = false;
- value = parsePropertyFunction(methodNode, options, false);
- state.allowYield = previousAllowYield;
+ ch = state.input.charCodeAt(state.position);
- return node.finishProperty('set', key, computed, value, false, false);
- }
- } else if (token.type === Token.Punctuator && token.value === '*' && lookaheadPropertyName()) {
- computed = match('[');
- key = parseObjectPropertyKey();
- methodNode = new Node();
+ if (ch === 0x5B/* [ */) {
+ terminator = 0x5D;/* ] */
+ isMapping = false;
+ _result = [];
+ } else if (ch === 0x7B/* { */) {
+ terminator = 0x7D;/* } */
+ isMapping = true;
+ _result = {};
+ } else {
+ return false;
+ }
- state.allowYield = true;
- params = parseParams();
- state.allowYield = previousAllowYield;
+ if (state.anchor !== null) {
+ state.anchorMap[state.anchor] = _result;
+ }
- state.allowYield = false;
- value = parsePropertyFunction(methodNode, params, true);
- state.allowYield = previousAllowYield;
+ ch = state.input.charCodeAt(++state.position);
- return node.finishProperty('init', key, computed, value, true, false);
- }
+ while (ch !== 0) {
+ skipSeparationSpace(state, true, nodeIndent);
- if (key && match('(')) {
- value = parsePropertyMethodFunction();
- return node.finishProperty('init', key, computed, value, true, false);
- }
+ ch = state.input.charCodeAt(state.position);
- // Not a MethodDefinition.
- return null;
+ if (ch === terminator) {
+ state.position++;
+ state.tag = _tag;
+ state.anchor = _anchor;
+ state.kind = isMapping ? 'mapping' : 'sequence';
+ state.result = _result;
+ return true;
+ } else if (!readNext) {
+ throwError(state, 'missed comma between flow collection entries');
}
- function parseObjectProperty(hasProto) {
- var token = lookahead, node = new Node(), computed, key, maybeMethod, proto, value;
+ keyTag = keyNode = valueNode = null;
+ isPair = isExplicitPair = false;
- computed = match('[');
- if (match('*')) {
- lex();
- } else {
- key = parseObjectPropertyKey();
- }
- maybeMethod = tryParseMethodDefinition(token, key, computed, node);
- if (maybeMethod) {
- return maybeMethod;
- }
+ if (ch === 0x3F/* ? */) {
+ following = state.input.charCodeAt(state.position + 1);
- if (!key) {
- throwUnexpectedToken(lookahead);
- }
+ if (is_WS_OR_EOL(following)) {
+ isPair = isExplicitPair = true;
+ state.position++;
+ skipSeparationSpace(state, true, nodeIndent);
+ }
+ }
- // Check for duplicated __proto__
- if (!computed) {
- proto = (key.type === Syntax.Identifier && key.name === '__proto__') ||
- (key.type === Syntax.Literal && key.value === '__proto__');
- if (hasProto.value && proto) {
- tolerateError(Messages.DuplicateProtoProperty);
- }
- hasProto.value |= proto;
- }
+ _line = state.line;
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
+ keyTag = state.tag;
+ keyNode = state.result;
+ skipSeparationSpace(state, true, nodeIndent);
- if (match(':')) {
- lex();
- value = inheritCoverGrammar(parseAssignmentExpression);
- return node.finishProperty('init', key, computed, value, false, false);
- }
+ ch = state.input.charCodeAt(state.position);
- if (token.type === Token.Identifier) {
- if (match('=')) {
- firstCoverInitializedNameError = lookahead;
- lex();
- value = isolateCoverGrammar(parseAssignmentExpression);
- return node.finishProperty('init', key, computed,
- new WrappingNode(token).finishAssignmentPattern(key, value), false, true);
- }
- return node.finishProperty('init', key, computed, key, false, true);
- }
+ if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
+ isPair = true;
+ ch = state.input.charCodeAt(++state.position);
+ skipSeparationSpace(state, true, nodeIndent);
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
+ valueNode = state.result;
+ }
- throwUnexpectedToken(lookahead);
+ if (isMapping) {
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
+ } else if (isPair) {
+ _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
+ } else {
+ _result.push(keyNode);
}
- function parseObjectInitializer() {
- var properties = [], hasProto = {value: false}, node = new Node();
+ skipSeparationSpace(state, true, nodeIndent);
- expect('{');
+ ch = state.input.charCodeAt(state.position);
- while (!match('}')) {
- properties.push(parseObjectProperty(hasProto));
+ if (ch === 0x2C/* , */) {
+ readNext = true;
+ ch = state.input.charCodeAt(++state.position);
+ } else {
+ readNext = false;
+ }
+ }
- if (!match('}')) {
- expectCommaSeparator();
- }
- }
+ throwError(state, 'unexpected end of the stream within a flow collection');
+}
- expect('}');
+function readBlockScalar(state, nodeIndent) {
+ var captureStart,
+ folding,
+ chomping = CHOMPING_CLIP,
+ detectedIndent = false,
+ textIndent = nodeIndent,
+ emptyLines = 0,
+ atMoreIndented = false,
+ tmp,
+ ch;
- return node.finishObjectExpression(properties);
- }
+ ch = state.input.charCodeAt(state.position);
- function reinterpretExpressionAsPattern(expr) {
- var i;
- switch (expr.type) {
- case Syntax.Identifier:
- case Syntax.MemberExpression:
- case Syntax.RestElement:
- case Syntax.AssignmentPattern:
- break;
- case Syntax.SpreadElement:
- expr.type = Syntax.RestElement;
- reinterpretExpressionAsPattern(expr.argument);
- break;
- case Syntax.ArrayExpression:
- expr.type = Syntax.ArrayPattern;
- for (i = 0; i < expr.elements.length; i++) {
- if (expr.elements[i] !== null) {
- reinterpretExpressionAsPattern(expr.elements[i]);
- }
- }
- break;
- case Syntax.ObjectExpression:
- expr.type = Syntax.ObjectPattern;
- for (i = 0; i < expr.properties.length; i++) {
- reinterpretExpressionAsPattern(expr.properties[i].value);
- }
- break;
- case Syntax.AssignmentExpression:
- expr.type = Syntax.AssignmentPattern;
- reinterpretExpressionAsPattern(expr.left);
- break;
- default:
- // Allow other node type for tolerant parsing.
- break;
- }
- }
+ if (ch === 0x7C/* | */) {
+ folding = false;
+ } else if (ch === 0x3E/* > */) {
+ folding = true;
+ } else {
+ return false;
+ }
- // ECMA-262 12.2.9 Template Literals
+ state.kind = 'scalar';
+ state.result = '';
- function parseTemplateElement(option) {
- var node, token;
+ while (ch !== 0) {
+ ch = state.input.charCodeAt(++state.position);
- if (lookahead.type !== Token.Template || (option.head && !lookahead.head)) {
- throwUnexpectedToken();
- }
+ if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
+ if (CHOMPING_CLIP === chomping) {
+ chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
+ } else {
+ throwError(state, 'repeat of a chomping mode identifier');
+ }
- node = new Node();
- token = lex();
+ } else if ((tmp = fromDecimalCode(ch)) >= 0) {
+ if (tmp === 0) {
+ throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
+ } else if (!detectedIndent) {
+ textIndent = nodeIndent + tmp - 1;
+ detectedIndent = true;
+ } else {
+ throwError(state, 'repeat of an indentation width identifier');
+ }
- return node.finishTemplateElement({ raw: token.value.raw, cooked: token.value.cooked }, token.tail);
+ } else {
+ break;
}
+ }
- function parseTemplateLiteral() {
- var quasi, quasis, expressions, node = new Node();
-
- quasi = parseTemplateElement({ head: true });
- quasis = [quasi];
- expressions = [];
-
- while (!quasi.tail) {
- expressions.push(parseExpression());
- quasi = parseTemplateElement({ head: false });
- quasis.push(quasi);
- }
+ if (is_WHITE_SPACE(ch)) {
+ do { ch = state.input.charCodeAt(++state.position); }
+ while (is_WHITE_SPACE(ch));
- return node.finishTemplateLiteral(quasis, expressions);
+ if (ch === 0x23/* # */) {
+ do { ch = state.input.charCodeAt(++state.position); }
+ while (!is_EOL(ch) && (ch !== 0));
}
+ }
- // ECMA-262 12.2.10 The Grouping Operator
+ while (ch !== 0) {
+ readLineBreak(state);
+ state.lineIndent = 0;
- function parseGroupExpression() {
- var expr, expressions, startToken, i, params = [];
+ ch = state.input.charCodeAt(state.position);
- expect('(');
+ while ((!detectedIndent || state.lineIndent < textIndent) &&
+ (ch === 0x20/* Space */)) {
+ state.lineIndent++;
+ ch = state.input.charCodeAt(++state.position);
+ }
- if (match(')')) {
- lex();
- if (!match('=>')) {
- expect('=>');
- }
- return {
- type: PlaceHolders.ArrowParameterPlaceHolder,
- params: [],
- rawParams: []
- };
- }
+ if (!detectedIndent && state.lineIndent > textIndent) {
+ textIndent = state.lineIndent;
+ }
- startToken = lookahead;
- if (match('...')) {
- expr = parseRestElement(params);
- expect(')');
- if (!match('=>')) {
- expect('=>');
- }
- return {
- type: PlaceHolders.ArrowParameterPlaceHolder,
- params: [expr]
- };
- }
+ if (is_EOL(ch)) {
+ emptyLines++;
+ continue;
+ }
- isBindingElement = true;
- expr = inheritCoverGrammar(parseAssignmentExpression);
+ // End of the scalar.
+ if (state.lineIndent < textIndent) {
- if (match(',')) {
- isAssignmentTarget = false;
- expressions = [expr];
+ // Perform the chomping.
+ if (chomping === CHOMPING_KEEP) {
+ state.result += common.repeat('\n', emptyLines);
+ } else if (chomping === CHOMPING_CLIP) {
+ if (detectedIndent) { // i.e. only if the scalar is not empty.
+ state.result += '\n';
+ }
+ }
- while (startIndex < length) {
- if (!match(',')) {
- break;
- }
- lex();
+ // Break this `while` cycle and go to the funciton's epilogue.
+ break;
+ }
- if (match('...')) {
- if (!isBindingElement) {
- throwUnexpectedToken(lookahead);
- }
- expressions.push(parseRestElement(params));
- expect(')');
- if (!match('=>')) {
- expect('=>');
- }
- isBindingElement = false;
- for (i = 0; i < expressions.length; i++) {
- reinterpretExpressionAsPattern(expressions[i]);
- }
- return {
- type: PlaceHolders.ArrowParameterPlaceHolder,
- params: expressions
- };
- }
+ // Folded style: use fancy rules to handle line breaks.
+ if (folding) {
- expressions.push(inheritCoverGrammar(parseAssignmentExpression));
- }
+ // Lines starting with white space characters (more-indented lines) are not folded.
+ if (is_WHITE_SPACE(ch)) {
+ atMoreIndented = true;
+ state.result += common.repeat('\n', emptyLines + 1);
+
+ // End of more-indented block.
+ } else if (atMoreIndented) {
+ atMoreIndented = false;
+ state.result += common.repeat('\n', emptyLines + 1);
- expr = new WrappingNode(startToken).finishSequenceExpression(expressions);
+ // Just one line break - perceive as the same line.
+ } else if (emptyLines === 0) {
+ if (detectedIndent) { // i.e. only if we have already read some scalar content.
+ state.result += ' ';
}
+ // Several line breaks - perceive as different lines.
+ } else {
+ state.result += common.repeat('\n', emptyLines);
+ }
- expect(')');
+ // Literal style: just add exact number of line breaks between content lines.
+ } else if (detectedIndent) {
+ // If current line isn't the first one - count line break from the last content line.
+ state.result += common.repeat('\n', emptyLines + 1);
+ } else {
+ // In case of the first content line - count only empty lines.
+ state.result += common.repeat('\n', emptyLines);
+ }
- if (match('=>')) {
- if (expr.type === Syntax.Identifier && expr.name === 'yield') {
- return {
- type: PlaceHolders.ArrowParameterPlaceHolder,
- params: [expr]
- };
- }
+ detectedIndent = true;
+ emptyLines = 0;
+ captureStart = state.position;
- if (!isBindingElement) {
- throwUnexpectedToken(lookahead);
- }
+ while (!is_EOL(ch) && (ch !== 0)) {
+ ch = state.input.charCodeAt(++state.position);
+ }
- if (expr.type === Syntax.SequenceExpression) {
- for (i = 0; i < expr.expressions.length; i++) {
- reinterpretExpressionAsPattern(expr.expressions[i]);
- }
- } else {
- reinterpretExpressionAsPattern(expr);
- }
+ captureSegment(state, captureStart, state.position, false);
+ }
- expr = {
- type: PlaceHolders.ArrowParameterPlaceHolder,
- params: expr.type === Syntax.SequenceExpression ? expr.expressions : [expr]
- };
- }
- isBindingElement = false;
- return expr;
- }
+ return true;
+}
+function readBlockSequence(state, nodeIndent) {
+ var _line,
+ _tag = state.tag,
+ _anchor = state.anchor,
+ _result = [],
+ following,
+ detected = false,
+ ch;
- // ECMA-262 12.2 Primary Expressions
+ if (state.anchor !== null) {
+ state.anchorMap[state.anchor] = _result;
+ }
- function parsePrimaryExpression() {
- var type, token, expr, node;
+ ch = state.input.charCodeAt(state.position);
- if (match('(')) {
- isBindingElement = false;
- return inheritCoverGrammar(parseGroupExpression);
- }
+ while (ch !== 0) {
- if (match('[')) {
- return inheritCoverGrammar(parseArrayInitializer);
- }
+ if (ch !== 0x2D/* - */) {
+ break;
+ }
- if (match('{')) {
- return inheritCoverGrammar(parseObjectInitializer);
- }
+ following = state.input.charCodeAt(state.position + 1);
- type = lookahead.type;
- node = new Node();
+ if (!is_WS_OR_EOL(following)) {
+ break;
+ }
- if (type === Token.Identifier) {
- if (state.sourceType === 'module' && lookahead.value === 'await') {
- tolerateUnexpectedToken(lookahead);
- }
- expr = node.finishIdentifier(lex().value);
- } else if (type === Token.StringLiteral || type === Token.NumericLiteral) {
- isAssignmentTarget = isBindingElement = false;
- if (strict && lookahead.octal) {
- tolerateUnexpectedToken(lookahead, Messages.StrictOctalLiteral);
- }
- expr = node.finishLiteral(lex());
- } else if (type === Token.Keyword) {
- if (!strict && state.allowYield && matchKeyword('yield')) {
- return parseNonComputedProperty();
- }
- if (!strict && matchKeyword('let')) {
- return node.finishIdentifier(lex().value);
- }
- isAssignmentTarget = isBindingElement = false;
- if (matchKeyword('function')) {
- return parseFunctionExpression();
- }
- if (matchKeyword('this')) {
- lex();
- return node.finishThisExpression();
- }
- if (matchKeyword('class')) {
- return parseClassExpression();
- }
- throwUnexpectedToken(lex());
- } else if (type === Token.BooleanLiteral) {
- isAssignmentTarget = isBindingElement = false;
- token = lex();
- token.value = (token.value === 'true');
- expr = node.finishLiteral(token);
- } else if (type === Token.NullLiteral) {
- isAssignmentTarget = isBindingElement = false;
- token = lex();
- token.value = null;
- expr = node.finishLiteral(token);
- } else if (match('/') || match('/=')) {
- isAssignmentTarget = isBindingElement = false;
- index = startIndex;
-
- if (typeof extra.tokens !== 'undefined') {
- token = collectRegex();
- } else {
- token = scanRegExp();
- }
- lex();
- expr = node.finishLiteral(token);
- } else if (type === Token.Template) {
- expr = parseTemplateLiteral();
- } else {
- throwUnexpectedToken(lex());
- }
+ detected = true;
+ state.position++;
- return expr;
+ if (skipSeparationSpace(state, true, -1)) {
+ if (state.lineIndent <= nodeIndent) {
+ _result.push(null);
+ ch = state.input.charCodeAt(state.position);
+ continue;
+ }
}
- // ECMA-262 12.3 Left-Hand-Side Expressions
+ _line = state.line;
+ composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
+ _result.push(state.result);
+ skipSeparationSpace(state, true, -1);
- function parseArguments() {
- var args = [], expr;
+ ch = state.input.charCodeAt(state.position);
- expect('(');
+ if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
+ throwError(state, 'bad indentation of a sequence entry');
+ } else if (state.lineIndent < nodeIndent) {
+ break;
+ }
+ }
- if (!match(')')) {
- while (startIndex < length) {
- if (match('...')) {
- expr = new Node();
- lex();
- expr.finishSpreadElement(isolateCoverGrammar(parseAssignmentExpression));
- } else {
- expr = isolateCoverGrammar(parseAssignmentExpression);
- }
- args.push(expr);
- if (match(')')) {
- break;
- }
- expectCommaSeparator();
- }
- }
+ if (detected) {
+ state.tag = _tag;
+ state.anchor = _anchor;
+ state.kind = 'sequence';
+ state.result = _result;
+ return true;
+ }
+ return false;
+}
- expect(')');
+function readBlockMapping(state, nodeIndent, flowIndent) {
+ var following,
+ allowCompact,
+ _line,
+ _tag = state.tag,
+ _anchor = state.anchor,
+ _result = {},
+ overridableKeys = {},
+ keyTag = null,
+ keyNode = null,
+ valueNode = null,
+ atExplicitKey = false,
+ detected = false,
+ ch;
- return args;
- }
+ if (state.anchor !== null) {
+ state.anchorMap[state.anchor] = _result;
+ }
+
+ ch = state.input.charCodeAt(state.position);
- function parseNonComputedProperty() {
- var token, node = new Node();
+ while (ch !== 0) {
+ following = state.input.charCodeAt(state.position + 1);
+ _line = state.line; // Save the current line.
- token = lex();
+ //
+ // Explicit notation case. There are two separate blocks:
+ // first for the key (denoted by "?") and second for the value (denoted by ":")
+ //
+ if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
- if (!isIdentifierName(token)) {
- throwUnexpectedToken(token);
+ if (ch === 0x3F/* ? */) {
+ if (atExplicitKey) {
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
+ keyTag = keyNode = valueNode = null;
}
- return node.finishIdentifier(token.value);
- }
+ detected = true;
+ atExplicitKey = true;
+ allowCompact = true;
+
+ } else if (atExplicitKey) {
+ // i.e. 0x3A/* : */ === character after the explicit key.
+ atExplicitKey = false;
+ allowCompact = true;
- function parseNonComputedMember() {
- expect('.');
+ } else {
+ throwError(state, 'incomplete explicit mapping pair; a key node is missed');
+ }
- return parseNonComputedProperty();
- }
+ state.position += 1;
+ ch = following;
- function parseComputedMember() {
- var expr;
+ //
+ // Implicit notation case. Flow-style node as the key first, then ":", and the value.
+ //
+ } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
- expect('[');
+ if (state.line === _line) {
+ ch = state.input.charCodeAt(state.position);
- expr = isolateCoverGrammar(parseExpression);
+ while (is_WHITE_SPACE(ch)) {
+ ch = state.input.charCodeAt(++state.position);
+ }
- expect(']');
+ if (ch === 0x3A/* : */) {
+ ch = state.input.charCodeAt(++state.position);
- return expr;
- }
+ if (!is_WS_OR_EOL(ch)) {
+ throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
+ }
- // ECMA-262 12.3.3 The new Operator
+ if (atExplicitKey) {
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
+ keyTag = keyNode = valueNode = null;
+ }
- function parseNewExpression() {
- var callee, args, node = new Node();
+ detected = true;
+ atExplicitKey = false;
+ allowCompact = false;
+ keyTag = state.tag;
+ keyNode = state.result;
- expectKeyword('new');
+ } else if (detected) {
+ throwError(state, 'can not read an implicit mapping pair; a colon is missed');
- if (match('.')) {
- lex();
- if (lookahead.type === Token.Identifier && lookahead.value === 'target') {
- if (state.inFunctionBody) {
- lex();
- return node.finishMetaProperty('new', 'target');
- }
- }
- throwUnexpectedToken(lookahead);
+ } else {
+ state.tag = _tag;
+ state.anchor = _anchor;
+ return true; // Keep the result of `composeNode`.
}
- callee = isolateCoverGrammar(parseLeftHandSideExpression);
- args = match('(') ? parseArguments() : [];
+ } else if (detected) {
+ throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
- isAssignmentTarget = isBindingElement = false;
+ } else {
+ state.tag = _tag;
+ state.anchor = _anchor;
+ return true; // Keep the result of `composeNode`.
+ }
- return node.finishNewExpression(callee, args);
+ } else {
+ break; // Reading is done. Go to the epilogue.
}
- // ECMA-262 12.3.4 Function Calls
-
- function parseLeftHandSideExpressionAllowCall() {
- var quasi, expr, args, property, startToken, previousAllowIn = state.allowIn;
-
- startToken = lookahead;
- state.allowIn = true;
-
- if (matchKeyword('super') && state.inFunctionBody) {
- expr = new Node();
- lex();
- expr = expr.finishSuper();
- if (!match('(') && !match('.') && !match('[')) {
- throwUnexpectedToken(lookahead);
- }
+ //
+ // Common reading code for both explicit and implicit notations.
+ //
+ if (state.line === _line || state.lineIndent > nodeIndent) {
+ if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
+ if (atExplicitKey) {
+ keyNode = state.result;
} else {
- expr = inheritCoverGrammar(matchKeyword('new') ? parseNewExpression : parsePrimaryExpression);
+ valueNode = state.result;
}
+ }
- for (;;) {
- if (match('.')) {
- isBindingElement = false;
- isAssignmentTarget = true;
- property = parseNonComputedMember();
- expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);
- } else if (match('(')) {
- isBindingElement = false;
- isAssignmentTarget = false;
- args = parseArguments();
- expr = new WrappingNode(startToken).finishCallExpression(expr, args);
- } else if (match('[')) {
- isBindingElement = false;
- isAssignmentTarget = true;
- property = parseComputedMember();
- expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);
- } else if (lookahead.type === Token.Template && lookahead.head) {
- quasi = parseTemplateLiteral();
- expr = new WrappingNode(startToken).finishTaggedTemplateExpression(expr, quasi);
- } else {
- break;
- }
- }
- state.allowIn = previousAllowIn;
+ if (!atExplicitKey) {
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
+ keyTag = keyNode = valueNode = null;
+ }
+
+ skipSeparationSpace(state, true, -1);
+ ch = state.input.charCodeAt(state.position);
+ }
- return expr;
+ if (state.lineIndent > nodeIndent && (ch !== 0)) {
+ throwError(state, 'bad indentation of a mapping entry');
+ } else if (state.lineIndent < nodeIndent) {
+ break;
}
+ }
+
+ //
+ // Epilogue.
+ //
- // ECMA-262 12.3 Left-Hand-Side Expressions
+ // Special case: last mapping's node contains only the key in explicit notation.
+ if (atExplicitKey) {
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
+ }
- function parseLeftHandSideExpression() {
- var quasi, expr, property, startToken;
- assert(state.allowIn, 'callee of new expression always allow in keyword.');
+ // Expose the resulting mapping.
+ if (detected) {
+ state.tag = _tag;
+ state.anchor = _anchor;
+ state.kind = 'mapping';
+ state.result = _result;
+ }
- startToken = lookahead;
+ return detected;
+}
- if (matchKeyword('super') && state.inFunctionBody) {
- expr = new Node();
- lex();
- expr = expr.finishSuper();
- if (!match('[') && !match('.')) {
- throwUnexpectedToken(lookahead);
- }
- } else {
- expr = inheritCoverGrammar(matchKeyword('new') ? parseNewExpression : parsePrimaryExpression);
- }
+function readTagProperty(state) {
+ var _position,
+ isVerbatim = false,
+ isNamed = false,
+ tagHandle,
+ tagName,
+ ch;
- for (;;) {
- if (match('[')) {
- isBindingElement = false;
- isAssignmentTarget = true;
- property = parseComputedMember();
- expr = new WrappingNode(startToken).finishMemberExpression('[', expr, property);
- } else if (match('.')) {
- isBindingElement = false;
- isAssignmentTarget = true;
- property = parseNonComputedMember();
- expr = new WrappingNode(startToken).finishMemberExpression('.', expr, property);
- } else if (lookahead.type === Token.Template && lookahead.head) {
- quasi = parseTemplateLiteral();
- expr = new WrappingNode(startToken).finishTaggedTemplateExpression(expr, quasi);
- } else {
- break;
- }
- }
- return expr;
- }
+ ch = state.input.charCodeAt(state.position);
+
+ if (ch !== 0x21/* ! */) return false;
- // ECMA-262 12.4 Postfix Expressions
+ if (state.tag !== null) {
+ throwError(state, 'duplication of a tag property');
+ }
- function parsePostfixExpression() {
- var expr, token, startToken = lookahead;
+ ch = state.input.charCodeAt(++state.position);
- expr = inheritCoverGrammar(parseLeftHandSideExpressionAllowCall);
+ if (ch === 0x3C/* < */) {
+ isVerbatim = true;
+ ch = state.input.charCodeAt(++state.position);
- if (!hasLineTerminator && lookahead.type === Token.Punctuator) {
- if (match('++') || match('--')) {
- // ECMA-262 11.3.1, 11.3.2
- if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
- tolerateError(Messages.StrictLHSPostfix);
- }
+ } else if (ch === 0x21/* ! */) {
+ isNamed = true;
+ tagHandle = '!!';
+ ch = state.input.charCodeAt(++state.position);
- if (!isAssignmentTarget) {
- tolerateError(Messages.InvalidLHSInAssignment);
- }
+ } else {
+ tagHandle = '!';
+ }
- isAssignmentTarget = isBindingElement = false;
+ _position = state.position;
- token = lex();
- expr = new WrappingNode(startToken).finishPostfixExpression(token.value, expr);
- }
- }
+ if (isVerbatim) {
+ do { ch = state.input.charCodeAt(++state.position); }
+ while (ch !== 0 && ch !== 0x3E/* > */);
- return expr;
+ if (state.position < state.length) {
+ tagName = state.input.slice(_position, state.position);
+ ch = state.input.charCodeAt(++state.position);
+ } else {
+ throwError(state, 'unexpected end of the stream within a verbatim tag');
}
+ } else {
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
- // ECMA-262 12.5 Unary Operators
-
- function parseUnaryExpression() {
- var token, expr, startToken;
+ if (ch === 0x21/* ! */) {
+ if (!isNamed) {
+ tagHandle = state.input.slice(_position - 1, state.position + 1);
- if (lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword) {
- expr = parsePostfixExpression();
- } else if (match('++') || match('--')) {
- startToken = lookahead;
- token = lex();
- expr = inheritCoverGrammar(parseUnaryExpression);
- // ECMA-262 11.4.4, 11.4.5
- if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
- tolerateError(Messages.StrictLHSPrefix);
- }
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
+ throwError(state, 'named tag handle cannot contain such characters');
+ }
- if (!isAssignmentTarget) {
- tolerateError(Messages.InvalidLHSInAssignment);
- }
- expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
- isAssignmentTarget = isBindingElement = false;
- } else if (match('+') || match('-') || match('~') || match('!')) {
- startToken = lookahead;
- token = lex();
- expr = inheritCoverGrammar(parseUnaryExpression);
- expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
- isAssignmentTarget = isBindingElement = false;
- } else if (matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof')) {
- startToken = lookahead;
- token = lex();
- expr = inheritCoverGrammar(parseUnaryExpression);
- expr = new WrappingNode(startToken).finishUnaryExpression(token.value, expr);
- if (strict && expr.operator === 'delete' && expr.argument.type === Syntax.Identifier) {
- tolerateError(Messages.StrictDelete);
- }
- isAssignmentTarget = isBindingElement = false;
+ isNamed = true;
+ _position = state.position + 1;
} else {
- expr = parsePostfixExpression();
+ throwError(state, 'tag suffix cannot contain exclamation marks');
}
+ }
- return expr;
+ ch = state.input.charCodeAt(++state.position);
}
- function binaryPrecedence(token, allowIn) {
- var prec = 0;
-
- if (token.type !== Token.Punctuator && token.type !== Token.Keyword) {
- return 0;
- }
+ tagName = state.input.slice(_position, state.position);
- switch (token.value) {
- case '||':
- prec = 1;
- break;
+ if (PATTERN_FLOW_INDICATORS.test(tagName)) {
+ throwError(state, 'tag suffix cannot contain flow indicator characters');
+ }
+ }
- case '&&':
- prec = 2;
- break;
+ if (tagName && !PATTERN_TAG_URI.test(tagName)) {
+ throwError(state, 'tag name cannot contain such characters: ' + tagName);
+ }
- case '|':
- prec = 3;
- break;
+ if (isVerbatim) {
+ state.tag = tagName;
- case '^':
- prec = 4;
- break;
+ } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
+ state.tag = state.tagMap[tagHandle] + tagName;
- case '&':
- prec = 5;
- break;
+ } else if (tagHandle === '!') {
+ state.tag = '!' + tagName;
- case '==':
- case '!=':
- case '===':
- case '!==':
- prec = 6;
- break;
+ } else if (tagHandle === '!!') {
+ state.tag = 'tag:yaml.org,2002:' + tagName;
- case '<':
- case '>':
- case '<=':
- case '>=':
- case 'instanceof':
- prec = 7;
- break;
+ } else {
+ throwError(state, 'undeclared tag handle "' + tagHandle + '"');
+ }
- case 'in':
- prec = allowIn ? 7 : 0;
- break;
+ return true;
+}
- case '<<':
- case '>>':
- case '>>>':
- prec = 8;
- break;
+function readAnchorProperty(state) {
+ var _position,
+ ch;
- case '+':
- case '-':
- prec = 9;
- break;
+ ch = state.input.charCodeAt(state.position);
- case '*':
- case '/':
- case '%':
- prec = 11;
- break;
+ if (ch !== 0x26/* & */) return false;
- default:
- break;
- }
+ if (state.anchor !== null) {
+ throwError(state, 'duplication of an anchor property');
+ }
- return prec;
- }
+ ch = state.input.charCodeAt(++state.position);
+ _position = state.position;
- // ECMA-262 12.6 Multiplicative Operators
- // ECMA-262 12.7 Additive Operators
- // ECMA-262 12.8 Bitwise Shift Operators
- // ECMA-262 12.9 Relational Operators
- // ECMA-262 12.10 Equality Operators
- // ECMA-262 12.11 Binary Bitwise Operators
- // ECMA-262 12.12 Binary Logical Operators
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
+ ch = state.input.charCodeAt(++state.position);
+ }
- function parseBinaryExpression() {
- var marker, markers, expr, token, prec, stack, right, operator, left, i;
+ if (state.position === _position) {
+ throwError(state, 'name of an anchor node must contain at least one character');
+ }
- marker = lookahead;
- left = inheritCoverGrammar(parseUnaryExpression);
+ state.anchor = state.input.slice(_position, state.position);
+ return true;
+}
- token = lookahead;
- prec = binaryPrecedence(token, state.allowIn);
- if (prec === 0) {
- return left;
- }
- isAssignmentTarget = isBindingElement = false;
- token.prec = prec;
- lex();
+function readAlias(state) {
+ var _position, alias,
+ ch;
- markers = [marker, lookahead];
- right = isolateCoverGrammar(parseUnaryExpression);
+ ch = state.input.charCodeAt(state.position);
- stack = [left, token, right];
+ if (ch !== 0x2A/* * */) return false;
- while ((prec = binaryPrecedence(lookahead, state.allowIn)) > 0) {
+ ch = state.input.charCodeAt(++state.position);
+ _position = state.position;
- // Reduce: make a binary expression from the three topmost entries.
- while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
- right = stack.pop();
- operator = stack.pop().value;
- left = stack.pop();
- markers.pop();
- expr = new WrappingNode(markers[markers.length - 1]).finishBinaryExpression(operator, left, right);
- stack.push(expr);
- }
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
+ ch = state.input.charCodeAt(++state.position);
+ }
- // Shift.
- token = lex();
- token.prec = prec;
- stack.push(token);
- markers.push(lookahead);
- expr = isolateCoverGrammar(parseUnaryExpression);
- stack.push(expr);
- }
+ if (state.position === _position) {
+ throwError(state, 'name of an alias node must contain at least one character');
+ }
- // Final reduce to clean-up the stack.
- i = stack.length - 1;
- expr = stack[i];
- markers.pop();
- while (i > 1) {
- expr = new WrappingNode(markers.pop()).finishBinaryExpression(stack[i - 1].value, stack[i - 2], expr);
- i -= 2;
- }
+ alias = state.input.slice(_position, state.position);
- return expr;
- }
+ if (!state.anchorMap.hasOwnProperty(alias)) {
+ throwError(state, 'unidentified alias "' + alias + '"');
+ }
+ state.result = state.anchorMap[alias];
+ skipSeparationSpace(state, true, -1);
+ return true;
+}
- // ECMA-262 12.13 Conditional Operator
+function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
+ var allowBlockStyles,
+ allowBlockScalars,
+ allowBlockCollections,
+ indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this
').text('no content');
pre = $('').append(code);
- // JSON
+ // JSON
} else if (contentType === 'application/json' || /\+json$/.test(contentType)) {
var json = null;
try {
@@ -26015,35 +20731,35 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
code = $('
').text(json);
pre = $('').append(code);
- // XML
+ // XML
} else if (contentType === 'application/xml' || /\+xml$/.test(contentType)) {
code = $('
').text(this.formatXml(content));
pre = $('').append(code);
- // HTML
+ // HTML
} else if (contentType === 'text/html') {
code = $('
').html(_.escape(content));
pre = $('').append(code);
- // Plain Text
+ // Plain Text
} else if (/text\/plain/.test(contentType)) {
code = $('
').text(content);
pre = $('').append(code);
- // Image
+ // Image
} else if (/^image\//.test(contentType)) {
pre = $('