Skip to content

Commit

Permalink
destructed = default
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascrockford committed Jan 28, 2019
1 parent de41376 commit eee020d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 60 deletions.
9 changes: 1 addition & 8 deletions help.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
<ul style="float: right; margin: 1em; padding-right: 12%;">
<li><a href="#try">Try it.</a></li>
<li><a href="https://www.amazon.com/dp/1949815005/wrrrldwideweb" target="_blank">
New book by Douglas Crockford: <i>How JavaScript Works</i>, on sale now.
<i>How JavaScript Works</i> by Douglas Crockford.
</a></li>
</ul>
<div id=title>Help</div>
Expand Down Expand Up @@ -435,13 +435,6 @@ <h1><code>/*jslint*/</code></h1>
<td><code>long</code></td>
<td><code>true</code> if a line can contain more than 80 characters.</td>
</tr>
<tr>
<td id="multivar">Tolerate multiple variables declarations per statement</td>
<td><code>multivar</code></td>
<td><code>true</code> if a <code>var</code>, <code>let</code>, or
<code>const</code> statement can declare two or more variables
in a single statement.</td>
</tr>
<tr>
<td id="node">Assume <a href="http://nodejs.org/">Node.js</a></td>
<td><code>node</code></td>
Expand Down
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<ul>
<li><a href="help.html">Read the instructions.</a></li>
<li><a href="https://www.amazon.com/dp/1949815005/wrrrldwideweb" target="_blank">
New book by Douglas Crockford: <i>How JavaScript Works</i>, on sale now.
<i>How JavaScript Works</i> by Douglas Crockford.
</a></li>
</ul>
</div>
Expand Down Expand Up @@ -95,7 +95,6 @@
<div><label><input title=for type=checkbox>for statement</label></div>
<div><label><input title=getset type=checkbox>get and set</label></div>
<div><label><input title=long type=checkbox>long lines</label></div>
<div><label><input title=multivar type=checkbox>multiple vars</label></div>
<div><label><input title=single type=checkbox>single quote strings</label></div>
<div><label><input title=this type=checkbox>this</label></div>
<div><label><input title=white type=checkbox>whitespace mess</label></div>
Expand Down
113 changes: 63 additions & 50 deletions jslint.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// jslint.js
// 2018-11-13
// 2018-11-28
// Copyright (c) 2015 Douglas Crockford (www.JSLint.com)

// Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -89,10 +89,10 @@
a, and, arity, assign, b, bad_assignment_a, bad_directive_a, bad_get,
bad_module_name_a, bad_option_a, bad_property_a, bad_set, bitwise, block,
body, browser, c, calls, catch, charCodeAt, closer, closure, code, column,
complex, concat, constant, context, convert, couch, create, d, dead,
default, devel, directive, directives, disrupt, dot, duplicate_a, edition,
ellipsis, else, empty_block, escape_mega, eval, every, expected_a,
expected_a_at_b_c, expected_a_b, expected_a_b_from_c_d, expected_a_before_b,
concat, constant, context, convert, couch, create, d, dead, default, devel,
directive, directives, disrupt, dot, duplicate_a, edition, ellipsis, else,
empty_block, escape_mega, eval, every, expected_a, expected_a_at_b_c,
expected_a_b, expected_a_b_from_c_d, expected_a_before_b,
expected_a_next_at_b, expected_digits_after_a, expected_four_digits,
expected_identifier_a, expected_line_break_a_b, expected_regexp_factor_a,
expected_space_a_b, expected_statements_a, expected_string_a,
Expand All @@ -102,8 +102,8 @@
inc, indexOf, infix_in, init, initial, isArray, isNaN, join, json, keys,
label, label_a, lbp, led, length, level, line, lines, live, long, loop, m,
margin, match, message, misplaced_a, misplaced_directive_a, missing_browser,
missing_m, module, multivar, naked_block, name, names, nested_comment, new,
node, not_label_a, nr, nud, number_isNaN, ok, open, opening, option,
missing_m, module, naked_block, name, names, nested_comment, new, node,
not_label_a, nr, nud, number_isNaN, ok, open, opening, option,
out_of_scope_a, parameters, parent, pop, property, push, quote,
redefinition_a_b, replace, required_a_optional_b, reserved_a, role, search,
shebang, signature, single, slice, some, sort, split, startsWith, statement,
Expand Down Expand Up @@ -170,7 +170,6 @@ const allowed_option = {
fudge: true,
getset: true,
long: true,
multivar: true,
node: [
"Buffer", "clearImmediate", "clearInterval", "clearTimeout",
"console", "exports", "module", "process", "require",
Expand Down Expand Up @@ -425,6 +424,7 @@ let fudge; // true if the natural numbers start with 1.
let functionage; // The current function.
let functions; // The array containing all of the functions.
let global; // The global object; the outermost context.
let implied_strict; // true if "use strict" is not needed.
let json_mode; // true if parsing JSON.
let lines; // The array containing source lines.
let mega_mode; // true if currently parsing a megastring literal.
Expand Down Expand Up @@ -760,11 +760,11 @@ function tokenize(source) {
// Make the token object and append it to the tokens list.

const the_token = {
from: from,

This comment has been minimized.

Copy link
@EvgenyOrekhov

EvgenyOrekhov Jan 31, 2019

Maybe JSLint should suggest using shorthand properties where possible?

This comment has been minimized.

Copy link
@douglascrockford

douglascrockford Jan 31, 2019

Author Collaborator

I agree.

This comment has been minimized.

Copy link
@kaizhu256

kaizhu256 via email Jan 31, 2019

Member

This comment has been minimized.

Copy link
@douglascrockford

douglascrockford Feb 1, 2019

Author Collaborator

JSLint already allowed the shorthand. Recommending the shorthand should not alter anything for you. It just makes the programs smaller, which seems to be what you are after.

id: id,
from,
id,
identifier: Boolean(identifier),
line: line,
nr: nr,
line,
nr,
thru: column
};
tokens[nr] = the_token;
Expand Down Expand Up @@ -2674,7 +2674,6 @@ prefix("void", function () {
});

function parameter_list() {
let complex = false;
const list = [];
let optional;
const signature = ["("];
Expand All @@ -2683,7 +2682,7 @@ function parameter_list() {
let ellipsis = false;
let param;
if (next_token.id === "{") {
complex = true;
implied_strict = true;
if (optional !== undefined) {
warn(
"required_a_optional_b",
Expand Down Expand Up @@ -2713,6 +2712,11 @@ function parameter_list() {
return stop("expected_identifier_a");
}
}
if (next_token.id === "=") {
advance("=");
subparam.expression = expression();
param.open = true;
}
param.names.push(subparam);
if (next_token.id === ",") {
advance(",");
Expand All @@ -2729,7 +2733,7 @@ function parameter_list() {
return parameter();
}
} else if (next_token.id === "[") {
complex = true;
implied_strict = true;
if (optional !== undefined) {
warn(
"required_a_optional_b",
Expand All @@ -2749,6 +2753,11 @@ function parameter_list() {
}
advance();
param.names.push(subparam);
if (next_token.id === "=") {
advance("=");
subparam.expression = expression();
param.open = true;
}
if (next_token.id === ",") {
advance(",");
return subparameter();
Expand All @@ -2763,7 +2772,7 @@ function parameter_list() {
}
} else {
if (next_token.id === "...") {
complex = true;
implied_strict = true;
ellipsis = true;
signature.push("...");
advance("...");
Expand All @@ -2787,7 +2796,7 @@ function parameter_list() {
param.ellipsis = true;
} else {
if (next_token.id === "=") {
complex = true;
implied_strict = true;
optional = param;
advance("=");
param.expression = expression(0);
Expand All @@ -2812,7 +2821,7 @@ function parameter_list() {
}
advance(")");
signature.push(")");
return [list, signature.join(""), complex];
return [list, signature.join("")];
}

function do_function(the_function) {
Expand Down Expand Up @@ -2885,10 +2894,7 @@ function do_function(the_function) {
advance("(");
token.free = false;
token.arity = "function";
const pl = parameter_list();
functionage.parameters = pl[0];
functionage.signature = pl[1];
functionage.complex = pl[2];
[functionage.parameters, functionage.signature] = parameter_list();
functionage.parameters.forEach(function enroll_parameter(name) {
if (name.identifier) {
enroll(name, "parameter", false);
Expand Down Expand Up @@ -2948,7 +2954,7 @@ function fart(pl) {
functionage = the_fart;
the_fart.parameters = pl[0];
the_fart.signature = pl[1];
the_fart.complex = true;
implied_strict = true;
the_fart.parameters.forEach(function (name) {
enroll(name, "parameter", true);
});
Expand Down Expand Up @@ -3153,7 +3159,7 @@ function do_var() {
(function next() {
if (next_token.id === "{" && the_statement.id !== "var") {
const the_brace = next_token;
the_brace.names = [];
implied_strict = true;
advance("{");
(function pair() {
if (!next_token.identifier) {
Expand All @@ -3168,26 +3174,33 @@ function do_var() {
return stop("expected_identifier_a", next_token);
}
next_token.label = name;
the_brace.names.push(next_token);
the_statement.names.push(next_token);
enroll(next_token, "variable", is_const);
advance();
the_brace.open = true;
} else {
the_brace.names.push(name);
the_statement.names.push(name);
enroll(name, "variable", is_const);
}
name.dead = false;
name.init = true;
if (next_token.id === "=") {
advance("=");
name.expression = expression();
the_brace.open = true;
}
if (next_token.id === ",") {
advance(",");
return pair();
}
}());
advance("}");
advance("=");
the_brace.expression = expression(0);
the_statement.names.push(the_brace);
the_statement.expression = expression(0);
} else if (next_token.id === "[" && the_statement.id !== "var") {
const the_bracket = next_token;
the_bracket.names = [];
advance("[");
implied_strict = true;
(function element() {
let ellipsis;
if (next_token.id === "...") {
Expand All @@ -3199,19 +3212,27 @@ function do_var() {
}
const name = next_token;
advance();
the_bracket.names.push(name);
enroll(name, "variable", the_statement.id === "const");
the_statement.names.push(name);
enroll(name, "variable", is_const);
name.dead = false;
name.init = true;
if (ellipsis) {
name.ellipsis = true;
} else if (next_token.id === ",") {
advance(",");
return element();
} else {
if (next_token.id === "=") {
advance("=");
name.expression = expression();
the_bracket.open = true;
}
if (next_token.id === ",") {
advance(",");
return element();
}
}
}());
advance("]");
advance("=");
the_bracket.expression = expression(0);
the_statement.names.push(the_bracket);
the_statement.expression = expression(0);
} else if (next_token.identifier) {
const name = next_token;
advance();
Expand All @@ -3220,26 +3241,17 @@ function do_var() {
}
enroll(name, "variable", is_const);
if (next_token.id === "=" || is_const) {
implied_strict = true;
advance("=");
name.dead = false;
name.init = true;
name.expression = expression(0);
}
the_statement.names.push(name);
} else {
return stop("expected_identifier_a", next_token);
}
if (next_token.id === ",") {
if (!option.multivar) {
warn("expected_a_b", next_token, ";", ",");
}
advance(",");
return next();
}
}());
the_statement.open = (
the_statement.names.length > 1
&& the_statement.line !== the_statement.names[1].line
);
semicolon();
return the_statement;
}
Expand Down Expand Up @@ -3892,7 +3904,7 @@ function preaction_function(thing) {
if (
module_mode === true
|| global.strict !== undefined
|| thing.complex
|| implied_strict
) {
if (thing.id !== "=>" && thing.block.strict !== undefined) {
warn("unexpected_a", thing.block.strict);
Expand Down Expand Up @@ -4634,7 +4646,7 @@ function whitage() {
const new_closer = opener[left.id];
if (typeof new_closer === "string") {
if (new_closer !== right.id) {
opening = left.line !== right.line;
opening = left.open || (left.line !== right.line);
push();
closer = new_closer;
if (opening) {
Expand Down Expand Up @@ -4870,6 +4882,7 @@ export default Object.freeze(function jslint(
};
blockage = global;
functionage = global;
implied_strict = false;
json_mode = false;
mega_mode = false;
module_mode = false;
Expand Down Expand Up @@ -4946,7 +4959,7 @@ export default Object.freeze(function jslint(
}
return {
directives,
edition: "2018-11-13",
edition: "2018-11-28",
exports,
froms,
functions,
Expand Down

0 comments on commit eee020d

Please sign in to comment.