javascriptlint-commit Mailing List for JavaScript Lint (Page 4)
Status: Beta
Brought to you by:
matthiasmiller
You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
(42) |
Apr
(15) |
May
(2) |
Jun
|
Jul
|
Aug
(33) |
Sep
(3) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
|
Feb
|
Mar
(5) |
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
(43) |
Nov
(4) |
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(20) |
Oct
(23) |
Nov
|
Dec
(1) |
2014 |
Jan
(1) |
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(18) |
2018 |
Jan
(7) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(8) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <mat...@us...> - 2013-09-28 04:44:08
|
Revision: 312 http://sourceforge.net/p/javascriptlint/code/312 Author: matthiasmiller Date: 2013-09-28 04:44:05 +0000 (Sat, 28 Sep 2013) Log Message: ----------- #38 case with continue results in 'missing break statement' Treat CONTINUE as an exit point Modified Paths: -------------- trunk/javascriptlint/warnings.py trunk/tests/warnings/missing_break.js Modified: trunk/javascriptlint/warnings.py =================================================================== --- trunk/javascriptlint/warnings.py 2013-09-28 04:30:11 UTC (rev 311) +++ trunk/javascriptlint/warnings.py 2013-09-28 04:44:05 UTC (rev 312) @@ -202,6 +202,8 @@ exit_points.add(None) elif node.kind == tok.BREAK: exit_points = set([node]) + elif node.kind == tok.CONTINUE: + exit_points = set([node]) elif node.kind == tok.WITH: exit_points = _get_exit_points(node.kids[-1]) elif node.kind == tok.RETURN: Modified: trunk/tests/warnings/missing_break.js =================================================================== --- trunk/tests/warnings/missing_break.js 2013-09-28 04:30:11 UTC (rev 311) +++ trunk/tests/warnings/missing_break.js 2013-09-28 04:44:05 UTC (rev 312) @@ -102,5 +102,18 @@ break; } + for (;;) { + switch(i) { + case 1: + i++; + continue; + case 2: + if (i) + continue; + default: /*warning:missing_break*/ + break; + } + } + return ""; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2013-09-28 04:30:14
|
Revision: 311 http://sourceforge.net/p/javascriptlint/code/311 Author: matthiasmiller Date: 2013-09-28 04:30:11 +0000 (Sat, 28 Sep 2013) Log Message: ----------- Show test results when complete. Modified Paths: -------------- trunk/test.py trunk/tests/warnings/for_in_missing_identifier.js Modified: trunk/test.py =================================================================== --- trunk/test.py 2013-09-28 04:27:44 UTC (rev 310) +++ trunk/test.py 2013-09-28 04:30:11 UTC (rev 311) @@ -100,6 +100,11 @@ except TestError, error: haderrors = True print error + + if haderrors: + print '\nOne or more tests failed!' + else: + print '\nAll tests passed successfully.' sys.exit(haderrors) if __name__ == '__main__': Modified: trunk/tests/warnings/for_in_missing_identifier.js =================================================================== --- trunk/tests/warnings/for_in_missing_identifier.js 2013-09-28 04:27:44 UTC (rev 310) +++ trunk/tests/warnings/for_in_missing_identifier.js 2013-09-28 04:30:11 UTC (rev 311) @@ -1,12 +1,12 @@ /*jsl:option explicit*/ function for_in_missing_identifier(o) { - var prop; - for (prop in o) - o[prop]++; - - for (var prop2 in o) - o[prop2]++; + var prop; + for (prop in o) + o[prop]++; + + for (var prop2 in o) + o[prop2]++; - for (!prop in o) /*warning:for_in_missing_identifier*/ - o[prop]++; + for (!prop in o) /*warning:for_in_missing_identifier*/ + o[prop]++; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2013-09-28 04:27:48
|
Revision: 310 http://sourceforge.net/p/javascriptlint/code/310 Author: matthiasmiller Date: 2013-09-28 04:27:44 +0000 (Sat, 28 Sep 2013) Log Message: ----------- Fix traceback when dumping a script with syntax errors Modified Paths: -------------- trunk/javascriptlint/jsparse.py Modified: trunk/javascriptlint/jsparse.py =================================================================== --- trunk/javascriptlint/jsparse.py 2013-09-28 04:17:38 UTC (rev 309) +++ trunk/javascriptlint/jsparse.py 2013-09-28 04:27:44 UTC (rev 310) @@ -119,7 +119,7 @@ _dump_node(node, depth+1) def dump_tree(script): - def error_callback(line, col, msg): + def error_callback(line, col, msg, msg_args): print '(%i, %i): %s', (line, col, msg) node = parse(script, None, error_callback) _dump_node(node) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2013-09-28 04:17:43
|
Revision: 309 http://sourceforge.net/p/javascriptlint/code/309 Author: matthiasmiller Date: 2013-09-28 04:17:38 +0000 (Sat, 28 Sep 2013) Log Message: ----------- #39 require variable names in "for .. in" statements Modified Paths: -------------- trunk/javascriptlint/warnings.py Added Paths: ----------- trunk/tests/warnings/for_in_missing_identifier.js Modified: trunk/javascriptlint/warnings.py =================================================================== --- trunk/javascriptlint/warnings.py 2013-09-28 04:08:31 UTC (rev 308) +++ trunk/javascriptlint/warnings.py 2013-09-28 04:17:38 UTC (rev 309) @@ -100,6 +100,7 @@ 'anon_no_return_value': 'anonymous function does not always return value', 'unsupported_version': 'JavaScript {version} is not supported', 'incorrect_version': 'Expected /*jsl:content-type*/ control comment. The script was parsed with the wrong version.', + 'for_in_missing_identifier': 'for..in should have identifier on left side', } errors = { @@ -587,6 +588,13 @@ if not node.fn_name: _check_return_value(node) +@lookfor((tok.FOR, op.FORIN)) +def for_in_missing_identifier(node): + assert node.kids[0].kind == tok.IN + left, right = node.kids[0].kids + if not left.kind in (tok.VAR, tok.NAME): + raise LintWarning, left + @lookfor() def mismatch_ctrl_comments(node): pass Added: trunk/tests/warnings/for_in_missing_identifier.js =================================================================== --- trunk/tests/warnings/for_in_missing_identifier.js (rev 0) +++ trunk/tests/warnings/for_in_missing_identifier.js 2013-09-28 04:17:38 UTC (rev 309) @@ -0,0 +1,12 @@ +/*jsl:option explicit*/ +function for_in_missing_identifier(o) { + var prop; + for (prop in o) + o[prop]++; + + for (var prop2 in o) + o[prop2]++; + + for (!prop in o) /*warning:for_in_missing_identifier*/ + o[prop]++; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2013-09-28 04:08:33
|
Revision: 308 http://sourceforge.net/p/javascriptlint/code/308 Author: matthiasmiller Date: 2013-09-28 04:08:31 +0000 (Sat, 28 Sep 2013) Log Message: ----------- #42 Failure when input file is not utf-8 encoded Allow passing the input file encoding on the command line. Modified Paths: -------------- trunk/javascriptlint/conf.py trunk/javascriptlint/fs.py trunk/javascriptlint/jsl.py trunk/javascriptlint/lint.py trunk/test.py Modified: trunk/javascriptlint/conf.py =================================================================== --- trunk/javascriptlint/conf.py 2013-09-28 03:50:06 UTC (rev 307) +++ trunk/javascriptlint/conf.py 2013-09-28 04:08:31 UTC (rev 308) @@ -187,7 +187,7 @@ def loadfile(self, path): path = os.path.abspath(path) - conf = fs.readfile(path) + conf = fs.readfile(path, 'utf-8') try: self.loadtext(conf, dir=os.path.dirname(path)) except ConfError, error: Modified: trunk/javascriptlint/fs.py =================================================================== --- trunk/javascriptlint/fs.py 2013-09-28 03:50:06 UTC (rev 307) +++ trunk/javascriptlint/fs.py 2013-09-28 04:08:31 UTC (rev 308) @@ -2,8 +2,8 @@ import codecs import os -def readfile(path): - file = codecs.open(path, 'r', 'utf-8') +def readfile(path, encoding): + file = codecs.open(path, 'r', encoding) contents = file.read() if contents and contents[0] == unicode(codecs.BOM_UTF8, 'utf8'): contents = contents[1:] Modified: trunk/javascriptlint/jsl.py =================================================================== --- trunk/javascriptlint/jsl.py 2013-09-28 03:50:06 UTC (rev 307) +++ trunk/javascriptlint/jsl.py 2013-09-28 04:08:31 UTC (rev 308) @@ -20,17 +20,17 @@ 'errors': 0 } -def _dump(paths): +def _dump(paths, encoding): for path in paths: - script = fs.readfile(path) + script = fs.readfile(path, encoding) jsparse.dump_tree(script) -def _lint(paths, conf_, printpaths): +def _lint(paths, conf_, printpaths, encoding): def lint_error(path, line, col, errname, errdesc): _lint_results['warnings'] = _lint_results['warnings'] + 1 print util.format_error(conf_['output-format'], path, line, col, errname, errdesc) - lint.lint_files(paths, lint_error, conf=conf_, printpaths=printpaths) + lint.lint_files(paths, lint_error, encoding, conf=conf_, printpaths=printpaths) def _resolve_paths(path, recurse): # Build a list of directories @@ -97,6 +97,8 @@ help="suppress lint summary") add("--help:conf", dest="showdefaultconf", action="store_true", default=False, help="display the default configuration file") + add("--encoding", dest="encoding", metavar="ENCODING", default="utf-8", + help="encoding for input file(s)") parser.set_defaults(verbosity=1) options, args = parser.parse_args() @@ -138,9 +140,9 @@ else: paths.append(arg) if options.dump: - profile_func(_dump, paths) + profile_func(_dump, paths, options.encoding) else: - profile_func(_lint, paths, conf_, options.printlisting) + profile_func(_lint, paths, conf_, options.printlisting, options.encoding) if options.printsummary: print '\n%i error(s), %i warnings(s)' % (_lint_results['errors'], Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2013-09-28 03:50:06 UTC (rev 307) +++ trunk/javascriptlint/lint.py 2013-09-28 04:08:31 UTC (rev 308) @@ -286,14 +286,14 @@ else: assert False, 'Invalid internal tag type %s' % tag['type'] -def lint_files(paths, lint_error, conf=conf.Conf(), printpaths=True): - def lint_file(path, kind, jsversion): +def lint_files(paths, lint_error, encoding, conf=conf.Conf(), printpaths=True): + def lint_file(path, kind, jsversion, encoding): def import_script(import_path, jsversion): # The user can specify paths using backslashes (such as when # linting Windows scripts on a posix environment. import_path = import_path.replace('\\', os.sep) import_path = os.path.join(os.path.dirname(path), import_path) - return lint_file(import_path, 'js', jsversion) + return lint_file(import_path, 'js', jsversion, encoding) def _lint_error(*args): return lint_error(normpath, *args) @@ -302,7 +302,7 @@ return lint_cache[normpath] if printpaths: print normpath - contents = fs.readfile(path) + contents = fs.readfile(path, encoding) lint_cache[normpath] = _Script() script_parts = [] @@ -334,9 +334,9 @@ for path in paths: ext = os.path.splitext(path)[1] if ext.lower() in ['.htm', '.html']: - lint_file(path, 'html', None) + lint_file(path, 'html', None, encoding) else: - lint_file(path, 'js', None) + lint_file(path, 'js', None, encoding) def _lint_script_part(scriptpos, jsversion, script, script_cache, conf, ignores, report_native, report_lint, import_callback): Modified: trunk/test.py =================================================================== --- trunk/test.py 2013-09-28 03:50:06 UTC (rev 307) +++ trunk/test.py 2013-09-28 04:08:31 UTC (rev 308) @@ -61,7 +61,7 @@ else: unexpected_warnings.append(warning + (errdesc,)) - javascriptlint.lint.lint_files([path], lint_error, conf=conf) + javascriptlint.lint.lint_files([path], lint_error, 'utf-8', conf=conf) errors = [] if expected_warnings: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2013-09-28 03:50:11
|
Revision: 307 http://sourceforge.net/p/javascriptlint/code/307 Author: matthiasmiller Date: 2013-09-28 03:50:06 +0000 (Sat, 28 Sep 2013) Log Message: ----------- #43 Problem with identifiers as object properties Add test case to confirm this works. Added Paths: ----------- trunk/tests/bugs/sf-43-reserved_object_def.js Added: trunk/tests/bugs/sf-43-reserved_object_def.js =================================================================== --- trunk/tests/bugs/sf-43-reserved_object_def.js (rev 0) +++ trunk/tests/bugs/sf-43-reserved_object_def.js 2013-09-28 03:50:06 UTC (rev 307) @@ -0,0 +1,7 @@ +// Test future keywords as object properties. +function f() { + var record = { + class: 'A' + }; + return record.class; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2013-09-28 03:45:40
|
Revision: 306 http://sourceforge.net/p/javascriptlint/code/306 Author: matthiasmiller Date: 2013-09-28 03:45:38 +0000 (Sat, 28 Sep 2013) Log Message: ----------- #45 jsl: declarations should allow for surrounding spaces Modified Paths: -------------- trunk/javascriptlint/lint.py trunk/tests/control_comments/control_comments.js Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2013-09-28 03:38:24 UTC (rev 305) +++ trunk/javascriptlint/lint.py 2013-09-28 03:45:38 UTC (rev 306) @@ -48,13 +48,13 @@ def _parse_control_comment(comment): """ Returns None or (keyword, parms) """ - if comment.atom.lower().startswith('jsl:'): - control_comment = comment.atom[4:] - elif comment.atom.startswith('@') and comment.atom.endswith('@'): - control_comment = comment.atom[1:-1] + comment_atom = comment.atom.lower().strip() + if comment_atom.startswith('jsl:'): + control_comment = comment_atom[4:] + elif comment_atom.startswith('@') and comment_atom.endswith('@'): + control_comment = comment_atom[1:-1] else: return None - control_comment = control_comment.lower().rstrip() keywords = ( 'ignoreall', Modified: trunk/tests/control_comments/control_comments.js =================================================================== --- trunk/tests/control_comments/control_comments.js 2013-09-28 03:38:24 UTC (rev 305) +++ trunk/tests/control_comments/control_comments.js 2013-09-28 03:45:38 UTC (rev 306) @@ -32,10 +32,12 @@ // The following are illegal. Make sure jsl doesn't choke. /*jsl:*/ /*warning:jsl_cc_not_understood*/ - if (a) - { + if (a) { /*jsl:pass */ } + else if (b) { + /* jsl:pass */ //allow spaces on both sides + } /*jsl:ignoreal*/ /*warning:jsl_cc_not_understood*/ /*jsl:declarebogus*/ /*warning:jsl_cc_not_understood*/ /*jsl:declare bogus */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2013-09-28 03:38:26
|
Revision: 305 http://sourceforge.net/p/javascriptlint/code/305 Author: matthiasmiller Date: 2013-09-28 03:38:24 +0000 (Sat, 28 Sep 2013) Log Message: ----------- #41 python re-write doesn't support option explicit Move Edit Fix traceback mentioned in comment regarding invalid control comments Modified Paths: -------------- trunk/javascriptlint/lint.py trunk/tests/control_comments/control_comments.js Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2013-09-28 03:06:19 UTC (rev 304) +++ trunk/javascriptlint/lint.py 2013-09-28 03:38:24 UTC (rev 305) @@ -54,29 +54,28 @@ control_comment = comment.atom[1:-1] else: return None + control_comment = control_comment.lower().rstrip() - control_comments = { - 'ignoreall': (False), - 'ignore': (False), - 'end': (False), - 'option explicit': (False), - 'import': (True), - 'fallthru': (False), - 'pass': (False), - 'declare': (True), - 'unused': (True), - 'content-type': (True), - } - if control_comment.lower() in control_comments: - keyword = control_comment.lower() - else: - keyword = control_comment.lower().split()[0] - if not keyword in control_comments: - return None + keywords = ( + 'ignoreall', + 'ignore', + 'end', + 'option explicit', + 'import', + 'fallthru', + 'pass', + 'declare', + 'unused', + 'content-type', + ) + for keyword in keywords: + # The keyword must either match or be separated by a space. + if control_comment == keyword or \ + (control_comment.startswith(keyword) and \ + control_comment[len(keyword)].isspace()): + parms = control_comment[len(keyword):].strip() + return (comment, keyword, parms.strip()) - parms = control_comment[len(keyword):].strip() - return (comment, keyword, parms) - class Scope: """ Outer-level scopes will never be associated with a node. Inner-level scopes will always be associated with a node. Modified: trunk/tests/control_comments/control_comments.js =================================================================== --- trunk/tests/control_comments/control_comments.js 2013-09-28 03:06:19 UTC (rev 304) +++ trunk/tests/control_comments/control_comments.js 2013-09-28 03:38:24 UTC (rev 305) @@ -29,5 +29,15 @@ /* illegal - don't forget to end */ /*jsl:ignore*/ /*warning:mismatch_ctrl_comments*/ + + // The following are illegal. Make sure jsl doesn't choke. + /*jsl:*/ /*warning:jsl_cc_not_understood*/ + if (a) + { + /*jsl:pass */ + } + /*jsl:ignoreal*/ /*warning:jsl_cc_not_understood*/ + /*jsl:declarebogus*/ /*warning:jsl_cc_not_understood*/ + /*jsl:declare bogus */ } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2013-09-28 03:06:23
|
Revision: 304 http://sourceforge.net/p/javascriptlint/code/304 Author: matthiasmiller Date: 2013-09-28 03:06:19 +0000 (Sat, 28 Sep 2013) Log Message: ----------- Replace SpiderMonkey with a JavaScript parser written purely in JavaScript. Modified Paths: -------------- trunk/DEVELOPMENT trunk/INSTALL trunk/javascriptlint/jsparse.py trunk/javascriptlint/lint.py trunk/javascriptlint/warnings.py trunk/setup.py trunk/test.py trunk/tests/control_comments/conf-version.js trunk/tests/html/e4x.html trunk/tests/html/script_tag_in_js_comment.html trunk/tests/warnings/identifier_hides_another.js trunk/tests/warnings/spidermonkey/bad_backref.js trunk/tests/warnings/spidermonkey/invalid_backref.js trunk/tests/warnings/want_assign_or_call.js Added Paths: ----------- trunk/jsengine/ trunk/jsengine/__init__.py trunk/jsengine/parser/ trunk/jsengine/parser/__init__.py trunk/jsengine/parser/_constants_kind.py trunk/jsengine/parser/_constants_op.py trunk/jsengine/structs.py trunk/jsengine/tokenizer/ trunk/jsengine/tokenizer/__init__.py Removed Paths: ------------- trunk/Makefile.SpiderMonkey trunk/javascriptlint/pyspidermonkey/ trunk/javascriptlint/pyspidermonkey_/ trunk/javascriptlint/spidermonkey.py trunk/spidermonkey/ trunk/tests/warnings/spidermonkey/deprecated_usage.js Modified: trunk/DEVELOPMENT =================================================================== --- trunk/DEVELOPMENT 2011-12-02 18:49:10 UTC (rev 303) +++ trunk/DEVELOPMENT 2013-09-28 03:06:19 UTC (rev 304) @@ -15,17 +15,3 @@ > add test for syntax error > consider reimplementing abiguous_newline - -** UPGRADING SPIDERMONKEY - -Use the following command to upgrade SpiderMonkey. Replace X.X.X with the -version number. js-X.X.X is the directory containing the new version of -SpiderMonkey. Use a relative path for pretty commit messages. - -svn_load_dirs.pl \ - -t X.X.X \ - -p svn_load_dirs.conf \ - https://javascriptlint.svn.sourceforge.net/svnroot/javascriptlint/vendorsrc/Mozilla.org/js \ - current \ - js-X.X.X - Modified: trunk/INSTALL =================================================================== --- trunk/INSTALL 2011-12-02 18:49:10 UTC (rev 303) +++ trunk/INSTALL 2013-09-28 03:06:19 UTC (rev 304) @@ -1,14 +1,4 @@ -BUILDING FROM THE SUBVERSION TRUNK -* Windows Prequisites: - * Visual Studio 2008 Express - * Python 2.6 - * py2exe - * MozillaBuild (http://developer.mozilla.org/en/docs/Windows_Build_Prerequisites) - - Launch the MozillaBuild MSVC 9 batch file. (You may have to run this as an - Administrator on Windows Vista.) Run the commands in that shell. - On all platforms: $ python setup.py build Deleted: trunk/Makefile.SpiderMonkey =================================================================== --- trunk/Makefile.SpiderMonkey 2011-12-02 18:49:10 UTC (rev 303) +++ trunk/Makefile.SpiderMonkey 2013-09-28 03:06:19 UTC (rev 304) @@ -1,59 +0,0 @@ -## THIS IS AN INTERNAL MAKEFILE FOR setup.py -## DO NOT RUN THIS MAKEFILE DIRECTLY. - -SPIDERMONKEY_SRC=spidermonkey/src - -# Load the SpiderMonkey config to find the OS define -# Also use this for the SO_SUFFIX -DEPTH=$(SPIDERMONKEY_SRC) -include $(SPIDERMONKEY_SRC)/config.mk -SPIDERMONKEY_OS=$(firstword $(patsubst -D%, %, $(filter -DXP_%, $(OS_CFLAGS)))) - -ifdef USE_MSVC -JS_LIB=js32.lib -else -JS_LIB=libjs.a -endif - -BUILD_DIR=build/spidermonkey - -ORIG_LIB=$(SPIDERMONKEY_SRC)/$(OBJDIR)/$(JS_LIB) -COPY_LIB=$(BUILD_DIR)/$(JS_LIB) -ORIG_DLL=$(SPIDERMONKEY_SRC)/$(OBJDIR)/js32.dll -COPY_DLL_DIR=$(DISTUTILS_DIR)/javascriptlint -COPY_DLL_PATH=$(COPY_DLL_DIR)/js32.dll -OS_HEADER=$(BUILD_DIR)/js_operating_system.h -ORIG_JSAUTOCFG_H=$(SPIDERMONKEY_SRC)/$(OBJDIR)/jsautocfg.h -COPY_JSAUTOCFG_H=$(BUILD_DIR)/jsautocfg.h - -ALL_TARGETS=$(COPY_LIB) $(OS_HEADER) -ifndef PREBUILT_CPUCFG -ALL_TARGETS+=$(COPY_JSAUTOCFG_H) -endif - -ifeq ($(SPIDERMONKEY_OS),XP_WIN) -ALL_TARGETS+=$(COPY_DLL_PATH) -endif - -all: $(ALL_TARGETS) - -clean: - rm -f $(ORIG_LIB) - rm -Rf $(BUILD_DIR) - -$(BUILD_DIR): - mkdir -p $(BUILD_DIR) - -$(COPY_LIB): $(BUILD_DIR) $(ORIG_LIB) - cp $(ORIG_LIB) $(COPY_LIB) - -$(COPY_DLL_PATH): $(ORIG_DLL) - mkdir -p $(COPY_DLL_DIR) - cp $(ORIG_DLL) $(COPY_DLL_PATH) - -$(OS_HEADER): $(BUILD_DIR) - echo "#define $(SPIDERMONKEY_OS)" > $(OS_HEADER) - -$(COPY_JSAUTOCFG_H): $(ORIG_JSAUTOCFG_H) - cp $(ORIG_JSAUTOCFG_H) $(COPY_JSAUTOCFG_H) - Modified: trunk/javascriptlint/jsparse.py =================================================================== --- trunk/javascriptlint/jsparse.py 2011-12-02 18:49:10 UTC (rev 303) +++ trunk/javascriptlint/jsparse.py 2013-09-28 03:06:19 UTC (rev 304) @@ -1,155 +1,20 @@ #!/usr/bin/python # vim: ts=4 sw=4 expandtab """ Parses a script into nodes. """ -import bisect import re import unittest -import spidermonkey -from spidermonkey import tok, op -from util import JSVersion +import jsengine.parser +from jsengine.parser import kind as tok +from jsengine.parser import op +from jsengine.structs import * -_tok_names = dict(zip( - [getattr(tok, prop) for prop in dir(tok)], - ['tok.%s' % prop for prop in dir(tok)] -)) -_op_names = dict(zip( - [getattr(op, prop) for prop in dir(op)], - ['op.%s' % prop for prop in dir(op)] -)) +from .util import JSVersion -NodePos = spidermonkey.NodePos - -class NodePositions: - " Given a string, allows [x] lookups for NodePos line and column numbers." - def __init__(self, text, start_pos=None): - # Find the length of each line and incrementally sum all of the lengths - # to determine the ending position of each line. - self._start_pos = start_pos - self._lines = text.splitlines(True) - lines = [0] + [len(x) for x in self._lines] - for x in range(1, len(lines)): - lines[x] += lines[x-1] - self._line_offsets = lines - def from_offset(self, offset): - line = bisect.bisect(self._line_offsets, offset)-1 - col = offset - self._line_offsets[line] - if self._start_pos: - if line == 0: - col += self._start_pos.col - line += self._start_pos.line - return NodePos(line, col) - def to_offset(self, pos): - pos = self._to_rel_pos(pos) - offset = self._line_offsets[pos.line] + pos.col - assert offset <= self._line_offsets[pos.line+1] # out-of-bounds col num - return offset - def text(self, start, end): - assert start <= end - start, end = self._to_rel_pos(start), self._to_rel_pos(end) - # Trim the ending first in case it's a single line. - lines = self._lines[start.line:end.line+1] - lines[-1] = lines[-1][:end.col+1] - lines[0] = lines[0][start.col:] - return ''.join(lines) - def _to_rel_pos(self, pos): - " converts a position to a position relative to self._start_pos " - if not self._start_pos: - return pos - line, col = pos.line, pos.col - line -= self._start_pos.line - if line == 0: - col -= self._start_pos.col - assert line >= 0 and col >= 0 # out-of-bounds node position - return NodePos(line, col) - -class NodeRanges: - def __init__(self): - self._offsets = [] - def add(self, start, end): - i = bisect.bisect_left(self._offsets, start) - if i % 2 == 1: - i -= 1 - start = self._offsets[i] - - end = end + 1 - j = bisect.bisect_left(self._offsets, end) - if j % 2 == 1: - end = self._offsets[j] - j += 1 - - self._offsets[i:j] = [start,end] - def has(self, pos): - return bisect.bisect_right(self._offsets, pos) % 2 == 1 - -class _Node: - def add_child(self, node): - if node: - node.node_index = len(self.kids) - node.parent = self - self.kids.append(node) - - def start_pos(self): - try: - return self._start_pos - except AttributeError: - self._start_pos = NodePos(self._start_line, self._start_col) - return self._start_pos - - def end_pos(self): - try: - return self._end_pos - except AttributeError: - self._end_pos = NodePos(self._end_line, self._end_col) - return self._end_pos - - def __str__(self): - kind = self.kind - if not kind: - kind = '(none)' - return '%s>%s' % (_tok_names[kind], str(self.kids)) - - def is_equivalent(self, other, are_functions_equiv=False): - if not other: - return False - - # Bail out for functions - if not are_functions_equiv: - if self.kind == tok.FUNCTION: - return False - if self.kind == tok.LP and self.opcode == op.CALL: - return False - - if self.kind != other.kind: - return False - if self.opcode != other.opcode: - return False - - # Check atoms on names, properties, and string constants - if self.kind in (tok.NAME, tok.DOT, tok.STRING) and self.atom != other.atom: - return False - - # Check values on numbers - if self.kind == tok.NUMBER and self.dval != other.dval: - return False - - # Compare child nodes - if len(self.kids) != len(other.kids): - return False - for i in range(0, len(self.kids)): - # Watch for dead nodes - if not self.kids[i]: - if not other.kids[i]: return True - else: return False - if not self.kids[i].is_equivalent(other.kids[i]): - return False - - return True - def isvalidversion(jsversion): if jsversion is None: return True - return spidermonkey.is_valid_version(jsversion.version) + return jsengine.parser.is_valid_version(jsversion.version) def findpossiblecomments(script, node_positions): pos = 0 @@ -168,31 +33,18 @@ comment_text = script[match.start():match.end()] if comment_text.startswith('/*'): comment_text = comment_text[2:-2] - opcode = 'JSOP_C_COMMENT' + opcode = op.C_COMMENT else: comment_text = comment_text[2:] - opcode = 'JSOP_CPP_COMMENT' - opcode = opcode[5:].lower() + opcode = op.CPP_COMMENT start_offset = match.start() end_offset = match.end()-1 start_pos = node_positions.from_offset(start_offset) end_pos = node_positions.from_offset(end_offset) - kwargs = { - 'kind': 'COMMENT', - 'atom': comment_text, - 'opcode': opcode, - '_start_line': start_pos.line, - '_start_col': start_pos.col, - '_end_line': end_pos.line, - '_end_col': end_pos.col, - 'parent': None, - 'kids': [], - 'node_index': None - } - comment_node = _Node() - comment_node.__dict__.update(kwargs) + comment_node = ParseNode(kind.COMMENT, opcode, start_pos, end_pos, + comment_text, []) comments.append(comment_node) # Start searching immediately after the start of the comment in case @@ -203,28 +55,23 @@ """ All node positions will be relative to startpos. This allows scripts to be embedded in a file (for example, HTML). """ - def _wrapped_callback(line, col, msg): - assert msg.startswith('JSMSG_') - msg = msg[6:].lower() - error_callback(line, col, msg) - startpos = startpos or NodePos(0,0) jsversion = jsversion or JSVersion.default() - assert isvalidversion(jsversion) - return spidermonkey.parse(script, jsversion.version, jsversion.e4x, - _Node, _wrapped_callback, - startpos.line, startpos.col) + assert isvalidversion(jsversion), jsversion + if jsversion.e4x: + error_callback(startpos.line, startpos.col, 'e4x_deprecated', {}) + return jsengine.parser.parse(script, jsversion.version, + error_callback, + startpos) def filtercomments(possible_comments, node_positions, root_node): comment_ignore_ranges = NodeRanges() def process(node): - if node.kind == tok.NUMBER: - node.atom = node_positions.text(node.start_pos(), node.end_pos()) - elif node.kind == tok.STRING or \ + if node.kind == tok.STRING or \ (node.kind == tok.OBJECT and node.opcode == op.REGEXP): start_offset = node_positions.to_offset(node.start_pos()) - end_offset = node_positions.to_offset(node.end_pos()) - 1 + end_offset = node_positions.to_offset(node.end_pos()) comment_ignore_ranges.add(start_offset, end_offset) for kid in node.kids: if kid: @@ -249,7 +96,7 @@ def is_compilable_unit(script, jsversion): jsversion = jsversion or JSVersion.default() assert isvalidversion(jsversion) - return spidermonkey.is_compilable_unit(script, jsversion.version, jsversion.e4x) + return jsengine.parser.is_compilable_unit(script, jsversion.version) def _dump_node(node, depth=0): if node is None: @@ -258,7 +105,7 @@ print else: print ' '*depth, - print '%s, %s' % (_tok_names[node.kind], _op_names[node.opcode]) + print '%s, %s' % (repr(node.kind), repr(node.opcode)) print ' '*depth, print '%s - %s' % (node.start_pos(), node.end_pos()) if hasattr(node, 'atom'): @@ -379,22 +226,21 @@ for text, expected in tests: encountered = is_compilable_unit(text, JSVersion.default()) self.assertEquals(encountered, expected) - # NOTE: This seems like a bug. - self.assert_(is_compilable_unit("/* test", JSVersion.default())) + self.assert_(not is_compilable_unit("/* test", JSVersion.default())) class TestLineOffset(unittest.TestCase): def testErrorPos(self): def geterror(script, startpos): errors = [] - def onerror(line, col, msg): - errors.append((line, col, msg)) + def onerror(line, col, msg, msg_args): + errors.append((line, col, msg, msg_args)) parse(script, None, onerror, startpos) self.assertEquals(len(errors), 1) return errors[0] - self.assertEquals(geterror(' ?', None), (0, 1, 'syntax_error')) - self.assertEquals(geterror('\n ?', None), (1, 1, 'syntax_error')) - self.assertEquals(geterror(' ?', NodePos(1,1)), (1, 2, 'syntax_error')) - self.assertEquals(geterror('\n ?', NodePos(1,1)), (2, 1, 'syntax_error')) + self.assertEquals(geterror(' ?', None), (0, 1, 'syntax_error', {})) + self.assertEquals(geterror('\n ?', None), (1, 1, 'syntax_error', {})) + self.assertEquals(geterror(' ?', NodePos(1,1)), (1, 2, 'syntax_error', {})) + self.assertEquals(geterror('\n ?', NodePos(1,1)), (2, 1, 'syntax_error', {})) def testNodePos(self): def getnodepos(script, startpos): root = parse(script, None, None, startpos) Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2011-12-02 18:49:10 UTC (rev 303) +++ trunk/javascriptlint/lint.py 2013-09-28 03:06:19 UTC (rev 304) @@ -12,7 +12,8 @@ import unittest import util -from spidermonkey import tok, op +from jsengine.parser import kind as tok +from jsengine.parser import op _newline_kinds = ( 'eof', 'comma', 'dot', 'semi', 'colon', 'lc', 'rc', 'lp', 'rb', 'assign', @@ -96,6 +97,7 @@ def add_declaration(self, name, node, type_): assert type_ in ('arg', 'function', 'var'), \ 'Unrecognized identifier type: %s' % type_ + assert isinstance(name, basestring) self._identifiers[name] = { 'node': node, 'type': type_ @@ -339,10 +341,10 @@ def _lint_script_part(scriptpos, jsversion, script, script_cache, conf, ignores, report_native, report_lint, import_callback): - def parse_error(row, col, msg): + def parse_error(row, col, msg, msg_args): if not msg in ('anon_no_return_value', 'no_return_value', 'redeclared_var', 'var_hides_arg'): - parse_errors.append((jsparse.NodePos(row, col), msg)) + parse_errors.append((jsparse.NodePos(row, col), msg, msg_args)) def report(node, errname, pos=None, **errargs): if errname == 'empty_statement' and node.kind == tok.LC: @@ -411,8 +413,8 @@ root = jsparse.parse(script, jsversion, parse_error, scriptpos) if not root: # Report errors and quit. - for pos, msg in parse_errors: - report_native(pos, msg) + for pos, msg, msg_args in parse_errors: + report_native(pos, msg, msg_args) return comments = jsparse.filtercomments(possible_comments, node_positions, root) @@ -457,7 +459,7 @@ elif keyword == 'pass': passes.append(node) else: - if comment.opcode == 'c_comment': + if comment.opcode == op.C_COMMENT: # Look for nested C-style comments. nested_comment = comment.atom.find('/*') if nested_comment < 0 and comment.atom.endswith('/'): @@ -514,9 +516,9 @@ errdesc = warnings.format_error(errname, **errargs) _report(pos or node.start_pos(), errname, errdesc, True) - def report_native(pos, errname): - # TODO: Format the error. - _report(pos, errname, errname, False) + def report_native(pos, errname, errargs): + errdesc = warnings.format_error(errname, **errargs) + _report(pos, errname, errdesc, False) def _report(pos, errname, errdesc, require_key): try: @@ -581,7 +583,7 @@ if other and parent_scope == scope: # Only warn about duplications in this scope. # Other scopes will be checked later. - if other.kind == tok.FUNCTION and name in other.fn_args: + if other.kind == tok.NAME and other.opcode == op.ARGNAME: report(node, 'var_hides_arg', name=name) else: report(node, 'redeclared_var', name=name) @@ -612,7 +614,9 @@ _warn_or_declare(scopes[-1], node.fn_name, 'function', node, report) self._push_scope(node) for var_name in node.fn_args: - scopes[-1].add_declaration(var_name, node, 'arg') + if scopes[-1].get_identifier(var_name.atom): + report(var_name, 'duplicate_formal', name=var_name.atom) + scopes[-1].add_declaration(var_name.atom, var_name, 'arg') @visitation.visit('push', tok.LEXICALSCOPE, tok.WITH) def _push_scope(self, node): Deleted: trunk/javascriptlint/spidermonkey.py =================================================================== --- trunk/javascriptlint/spidermonkey.py 2011-12-02 18:49:10 UTC (rev 303) +++ trunk/javascriptlint/spidermonkey.py 2013-09-28 03:06:19 UTC (rev 304) @@ -1,10 +0,0 @@ -# vim: ts=4 sw=4 expandtab - -# This is a wrapper script to make it easier for development. It tries to -# import the development version first, and if that fails, it goes after the -# real version. -try: - from pyspidermonkey_ import * -except ImportError: - from pyspidermonkey import * - Modified: trunk/javascriptlint/warnings.py =================================================================== --- trunk/javascriptlint/warnings.py 2011-12-02 18:49:10 UTC (rev 303) +++ trunk/javascriptlint/warnings.py 2013-09-28 03:06:19 UTC (rev 304) @@ -21,9 +21,10 @@ import util import visitation -from spidermonkey import tok, op +from jsengine.parser import kind as tok +from jsengine.parser import op -_ALL_TOKENS = tuple(filter(lambda x: x != tok.EOF, tok.__dict__.values())) +_ALL_TOKENS = tok.__dict__.values() def _get_assigned_lambda(node): """ Given a node "x = function() {}", returns "function() {}". @@ -53,6 +54,7 @@ 'use_of_label': 'use of label', 'misplaced_regex': 'regular expressions should be preceded by a left parenthesis, assignment, colon, or comma', 'assign_to_function_call': 'assignment to a function call', + 'equal_as_assign': 'test for equality (==) mistyped as assignment (=)?', 'ambiguous_else_stmt': 'the else statement could be matched with one of multiple if statements (use curly braces to indicate intent', 'block_without_braces': 'block statement without curly braces', 'ambiguous_nested_stmt': 'block statements containing block statements should use curly braces to resolve ambiguity', @@ -70,6 +72,7 @@ 'leading_decimal_point': 'leading decimal point may indicate a number or an object member', 'trailing_decimal_point': 'trailing decimal point may indicate a number or an object member', 'octal_number': 'leading zeros make an octal number', + 'trailing_comma': 'extra comma is not recommended in object initializers', 'trailing_comma_in_array': 'extra comma is not recommended in array initializers', 'useless_quotes': 'the quotation marks are unnecessary', 'mismatch_ctrl_comments': 'mismatched control comment; "ignore" and "end" control comments must have a one-to-one correspondence', @@ -99,8 +102,20 @@ 'incorrect_version': 'Expected /*jsl:content-type*/ control comment. The script was parsed with the wrong version.', } +errors = { + 'e4x_deprecated': 'e4x is deprecated', + 'semi_before_stmnt': 'missing semicolon before statement', + 'syntax_error': 'syntax error', + 'expected_tok': 'expected token: {token}', + 'unexpected_char': 'unexpected character: {char}', +} + def format_error(errname, **errargs): - errdesc = warnings[errname] + if errname in errors: + errdesc = errors[errname] + else: + errdesc = warnings[errname] + try: errdesc = re.sub(r"{(\w+)}", lambda match: errargs[match.group(1)], errdesc) except (TypeError, KeyError): @@ -295,9 +310,18 @@ @lookfor(tok.ASSIGN) def assign_to_function_call(node): - if node.kids[0].kind == tok.LP: + kid = node.kids[0] + # Unpack parens. + while kid.kind == tok.RP: + kid, = kid.kids + if kid.kind == tok.LP: raise LintWarning, node +@lookfor(tok.ASSIGN) +def equal_as_assign(node): + if not node.parent.kind in (tok.SEMI, tok.RESERVED, tok.RP, tok.COMMA): + raise LintWarning, node + @lookfor(tok.IF) def ambiguous_else_stmt(node): # Only examine this node if it has an else statement. @@ -492,6 +516,11 @@ if _octal_regexp.match(node.atom): raise LintWarning, node +@lookfor(tok.RC) +def trailing_comma(node): + if node.end_comma: + raise LintWarning, node + @lookfor(tok.RB) def trailing_comma_in_array(node): if node.end_comma: Index: trunk/jsengine =================================================================== --- trunk/jsengine 2011-12-02 18:49:10 UTC (rev 303) +++ trunk/jsengine 2013-09-28 03:06:19 UTC (rev 304) Property changes on: trunk/jsengine ___________________________________________________________________ Added: svn:ignore ## -0,0 +1 ## +*.pyc Added: trunk/jsengine/__init__.py =================================================================== --- trunk/jsengine/__init__.py (rev 0) +++ trunk/jsengine/__init__.py 2013-09-28 03:06:19 UTC (rev 304) @@ -0,0 +1,21 @@ +# vim: sw=4 ts=4 et + +_MESSAGES = ( + 'eof', + 'semi_before_stmnt', + 'syntax_error', + 'unterminated_comment', + 'expected_tok', + 'unexpected_char', +) + +class JSSyntaxError(BaseException): + def __init__(self, pos, msg, msg_args=None): + assert msg in _MESSAGES, msg + self.pos = pos + self.msg = msg + self.msg_args = msg_args or {} + def __unicode__(self): + return '%s: %s' % (self.pos, self.msg) + def __repr__(self): + return 'JSSyntaxError(%r, %r, %r)' % (self.pos, self.msg. self.msg_args) Added: trunk/jsengine/parser/__init__.py =================================================================== --- trunk/jsengine/parser/__init__.py (rev 0) +++ trunk/jsengine/parser/__init__.py 2013-09-28 03:06:19 UTC (rev 304) @@ -0,0 +1,924 @@ +# vim: sw=4 ts=4 et +import unittest + +from jsengine.tokenizer import tok +from jsengine import tokenizer + +from jsengine import JSSyntaxError +from _constants_kind import kind +from _constants_op import op + +from jsengine.structs import * + +_VERSIONS = [ + "default", + "1.0", + "1.1", + "1.2", + "1.3", + "1.4", + "1.5", + "1.6", + "1.7", +] + +def _auto_semicolon(t, kind_, op_, startpos, endpos, atom, kids): + nosemi = False + if t.peek_sameline().tok not in (tok.EOF, tok.EOL, tok.RBRACE): + x = t.advance() + if x.tok != tok.SEMI: + raise JSSyntaxError(x.startpos, 'semi_before_stmnt') + endpos = x.endpos + else: + nosemi = True + return ParseNode(kind_, op_, startpos, endpos, atom, kids, nosemi) + +def _function_arglist(t): + fn_args = [] + if t.peek().tok != tok.RPAREN: + while True: + x = t.expect(tok.NAME) + fn_args.append(ParseNode(kind.NAME, op.ARGNAME, + x.startpos, + x.endpos, x.atom, [])) + if t.peek().tok == tok.COMMA: + t.advance() + else: + break + return fn_args + +def _primary_expression(t): + x = t.next_withregexp() + if x.tok == tok.THIS: + return ParseNode(kind.PRIMARY, op.THIS, x.startpos, x.endpos, None, []) + elif x.tok == tok.NAME: + return ParseNode(kind.NAME, op.NAME, x.startpos, x.endpos, x.atom, [None]) + elif x.tok == tok.NULL: + return ParseNode(kind.PRIMARY, op.NULL, x.startpos, x.endpos, None, []) + elif x.tok == tok.TRUE: + return ParseNode(kind.PRIMARY, op.TRUE, x.startpos, x.endpos, None, []) + elif x.tok == tok.FALSE: + return ParseNode(kind.PRIMARY, op.FALSE, x.startpos, x.endpos, None, []) + elif x.tok == tok.STRING: + return ParseNode(kind.STRING, op.STRING, x.startpos, x.endpos, x.atom, []) + elif x.tok == tok.REGEXP: + return ParseNode(kind.OBJECT, op.REGEXP, x.startpos, x.endpos, None, []) + elif x.tok == tok.NUMBER: + return ParseNode(kind.NUMBER, None, x.startpos, x.endpos, x.atom, []) + elif x.tok == tok.LBRACKET: + startpos = x.startpos + items = [] + end_comma = None + if t.peek().tok != tok.RBRACKET: + while True: + # Conditionally add a value. If it isn't followed by a comma, + # quit in order to force an RBRACKET. + if t.peek().tok == tok.COMMA: + items.append(None) + else: + items.append(_assignment_expression(t, True)) + if not t.peek().tok == tok.COMMA: + break + + # Expect a comma and use it if the value was missing. + x = t.expect(tok.COMMA) + comma = ParseNode(kind.COMMA, None, + x.startpos, x.endpos, None, []) + items[-1] = items[-1] or comma + + # Check for the end. + if t.peek().tok == tok.RBRACKET: + end_comma = comma + break + endpos = t.expect(tok.RBRACKET).endpos + return ParseNode(kind.RB, None, startpos, endpos, None, items, + end_comma=end_comma) + elif x.tok == tok.LBRACE: + startpos = x.startpos + kids = [] + # TODO: get/set + end_comma = None + while True: + x = t.peek() + if x.tok == tok.RBRACE: + break + elif x.tok == tok.STRING: + t.expect(tok.STRING) + key = ParseNode(kind.STRING, None, x.startpos, + x.endpos, x.atom, []) + elif x.tok == tok.NUMBER: + t.expect(tok.NUMBER) + key = ParseNode(kind.NUMBER, None, x.startpos, + x.endpos, x.atom, []) + else: + x = t.expect_identifiername() + key = ParseNode(kind.NAME, None, x.startpos, x.endpos, + x.atom, []) + t.expect(tok.COLON) + value = _assignment_expression(t, True) + kids.append(ParseNode(kind.COLON, None, key.startpos, + value.endpos, None, [key, value])) + if t.peek().tok == tok.COMMA: + x = t.advance() + end_comma = ParseNode(kind.COMMA, None, + x.startpos, x.endpos, None, []) + else: + end_comma = None + break + endpos = t.expect(tok.RBRACE).endpos + return ParseNode(kind.RC, None, startpos, endpos, None, kids, + end_comma=end_comma) + elif x.tok == tok.LPAREN: + startpos = x.startpos + kid = _expression(t, True) + endpos = t.expect(tok.RPAREN).endpos + return ParseNode(kind.RP, None, startpos, endpos, None, [kid]) + else: + raise JSSyntaxError(x.startpos, 'syntax_error') + +def _function_declaration(t, named_opcode): + node = _function_expression(t, named_opcode) + + # Convert anonymous functions in expressions. + if node.opcode == op.ANONFUNOBJ: + node = _auto_semicolon(t, kind.SEMI, None, node.startpos, node.endpos, + None, [node]) + return node + + +def _function_expression(t, named_opcode): + startpos = t.expect(tok.FUNCTION).startpos + if t.peek().tok == tok.NAME: + fn_name = t.expect(tok.NAME).atom + opcode = named_opcode + else: + fn_name = None + opcode = op.ANONFUNOBJ + t.expect(tok.LPAREN) + fn_args = _function_arglist(t) + t.expect(tok.RPAREN) + fn_body_startpos = t.expect(tok.LBRACE).startpos + kids = _sourceelements(t, tok.RBRACE) + fn_body_endpos = t.expect(tok.RBRACE).endpos + fn_body = ParseNode(kind.LC, None, fn_body_startpos, + fn_body_endpos, None, kids) + return ParseNode(kind.FUNCTION, + op.ANONFUNOBJ if fn_name is None else op.NAMEDFUNOBJ, + startpos, fn_body.endpos, + fn_name, [fn_body], fn_args=fn_args) + +def _argument_list(t): + args = [] + if t.peek().tok != tok.RPAREN: + while True: + args.append(_assignment_expression(t, True)) + if t.peek().tok == tok.COMMA: + t.advance() + else: + break + return args + +def _new_expression(t): + startpos = t.expect(tok.NEW).startpos + expr = _member_expression(t) + # If no (), this is a variant of the NewExpression + if t.peek().tok == tok.LPAREN: + t.expect(tok.LPAREN) + args = _argument_list(t) + endpos = t.expect(tok.RPAREN).endpos + else: + args = [] + endpos = expr.endpos + return ParseNode(kind.NEW, op.NEW, startpos, endpos, + None, [expr] + args) + +def _member_expression(t, _recurse=True): + x = t.peek() + if x.tok == tok.NEW: + kid = _new_expression(t) + elif x.tok == tok.FUNCTION: + kid = _function_expression(t, op.NAMEDFUNOBJ) + else: + kid = _primary_expression(t) + + while True: + if t.peek().tok == tok.LBRACKET: + t.advance() + expr = _expression(t, True) + endpos = t.expect(tok.RBRACKET).endpos + kid = ParseNode(kind.LB, op.GETELEM, kid.startpos, endpos, + None, [kid, expr]) + elif t.peek().tok == tok.DOT: + t.advance() + expr = t.expect_identifiername() + kid = ParseNode(kind.DOT, op.GETPROP, kid.startpos, expr.endpos, + expr.atom, [kid]) + else: + return kid + +def _call_expression(t): + expr = _member_expression(t) + if t.peek().tok != tok.LPAREN: + return expr + + while True: + x = t.peek() + if x.tok == tok.LPAREN: + t.expect(tok.LPAREN) + args = _argument_list(t) + endpos = t.expect(tok.RPAREN).endpos + expr = ParseNode(kind.LP, op.CALL, expr.startpos, + endpos, None, [expr] + args) + elif x.tok == tok.LBRACKET: + t.expect(tok.LBRACKET) + lookup = _expression(t, True) + endpos = t.expect(tok.RBRACKET).endpos + expr = ParseNode(kind.LB, op.GETELEM, + expr.startpos, endpos, + None, [expr, lookup]) + elif x.tok == tok.DOT: + t.expect(tok.DOT) + lookup = t.expect_identifiername() + expr = ParseNode(kind.DOT, op.GETPROP, + expr.startpos, lookup.endpos, + lookup.atom, [expr]) + else: + return expr + +def _lefthandside_expression(t): + kid = _call_expression(t) + kid._lefthandside = True + return kid + +def _postfix_expression(t): + kid = _lefthandside_expression(t) + if t.peek_sameline().tok == tok.INC: + endpos = t.expect(tok.INC).endpos + if kid.kind == kind.DOT and kid.opcode == op.GETPROP: + opcode = op.PROPINC + else: + opcode = op.NAMEINC + return ParseNode(kind.INC, opcode, + kid.startpos, endpos, None, [kid]) + elif t.peek_sameline().tok == tok.DEC: + endpos = t.expect(tok.DEC).endpos + return ParseNode(kind.DEC, op.NAMEDEC, + kid.startpos, endpos, None, [kid]) + else: + return kid + +_UNARY = { + tok.DELETE: (kind.DELETE, None), + tok.VOID: (kind.UNARYOP, op.VOID), + tok.TYPEOF: (kind.UNARYOP, op.TYPEOF), + tok.INC: (kind.INC, op.INCNAME), + tok.DEC: (kind.DEC, op.DECNAME), + tok.ADD: (kind.UNARYOP, op.POS), + tok.SUB: (kind.UNARYOP, op.NEG), + tok.BIT_NOT: (kind.UNARYOP, op.BITNOT), + tok.LOGICAL_NOT: (kind.UNARYOP, op.NOT), +} +def _unary_expression(t): + x = t.peek() + if x.tok in _UNARY: + kind_, op_ = _UNARY[x.tok] + startpos = t.advance().startpos + kid = _unary_expression(t) + return ParseNode(kind_, op_, startpos, kid.endpos, None, [kid]) + else: + return _postfix_expression(t) + +def _binary_expression(t, dict_, child_expr_callback): + expr = child_expr_callback(t) + while True: + x = t.peek() + try: + kind_, op_ = dict_[x.tok] + except KeyError: + return expr + + kids = [expr] + while t.peek().tok == x.tok: + t.advance() + kids.append(child_expr_callback(t)) + expr = ParseNode(kind_, op_, + kids[0].startpos, kids[1].endpos, + None, kids) + +_MULTIPLICATIVE = { + tok.MUL: (kind.STAR, op.MUL), + tok.DIV: (kind.DIVOP, op.DIV), + tok.MOD: (kind.DIVOP, op.MOD), +} +def _multiplicative_expression(t): + return _binary_expression(t, _MULTIPLICATIVE, _unary_expression) + +_ADDITIVE = { + tok.ADD: (kind.PLUS, op.ADD), + tok.SUB: (kind.MINUS, op.SUB), +} +def _additive_expression(t): + return _binary_expression(t, _ADDITIVE, + _multiplicative_expression) + +_SHIFT = { + tok.LSHIFT: (kind.SHOP, op.LSH), + tok.RSHIFT: (kind.SHOP, op.RSH), + tok.URSHIFT: (kind.SHOP, op.URSH), +} +def _shift_expression(t): + return _binary_expression(t, _SHIFT, + _additive_expression) + +_RELATIONAL_NOIN = { + tok.LT: (kind.RELOP, op.LT), + tok.GT: (kind.RELOP, op.GT), + tok.LE: (kind.RELOP, op.LE), + tok.GE: (kind.RELOP, op.GE), + tok.INSTANCEOF: (kind.INSTANCEOF, op.INSTANCEOF), +} +_RELATIONAL_IN = dict(_RELATIONAL_NOIN) +_RELATIONAL_IN.update({ + tok.IN: (kind.IN, op.IN), +}) +def _relational_expression(t, allowin): + return _binary_expression(t, _RELATIONAL_IN if allowin else _RELATIONAL_NOIN, + _shift_expression) + +_EQUALITY = { + tok.EQ: (kind.EQOP, op.EQ), + tok.NE: (kind.EQOP, op.NE), + tok.EQ_STRICT: (kind.EQOP, op.NEW_EQ), + tok.NE_STRICT: (kind.EQOP, op.NEW_NE), +} +def _equality_expression(t, allowin): + return _binary_expression(t, _EQUALITY, + lambda t: _relational_expression(t, allowin)) + +def _bitwise_and_expression(t, allowin): + left = _equality_expression(t, allowin) + while t.peek().tok == tok.BIT_AND: + t.advance() + right = _equality_expression(t, allowin) + left = ParseNode(kind.BITAND, op.BITAND, + left.startpos, right.endpos, + None, [left, right]) + return left + +def _bitwise_xor_expression(t, allowin): + left = _bitwise_and_expression(t, allowin) + while t.peek().tok == tok.BIT_XOR: + t.advance() + right = _bitwise_and_expression(t, allowin) + left = ParseNode(kind.BITXOR, op.BITXOR, + left.startpos, right.endpos, + None, [left, right]) + return left + +def _bitwise_or_expression(t, allowin): + left = _bitwise_xor_expression(t, allowin) + while t.peek().tok == tok.BIT_OR: + t.advance() + right = _bitwise_xor_expression(t, allowin) + left = ParseNode(kind.BITOR, op.BITOR, + left.startpos, right.endpos, + None, [left, right]) + return left + +def _logical_and_expression(t, allowin): + exprs = [] + while True: + exprs.append(_bitwise_or_expression(t, allowin)) + if t.peek().tok == tok.LOGICAL_AND: + t.expect(tok.LOGICAL_AND) + else: + break + + while len(exprs) > 1: + right = exprs.pop() + left = exprs[-1] + exprs[-1] = ParseNode(kind.AND, op.AND, + left.startpos, right.endpos, + None, [left, right]) + return exprs[0] + +def _logical_or_expression(t, allowin): + exprs = [] + while True: + exprs.append(_logical_and_expression(t, allowin)) + if t.peek().tok == tok.LOGICAL_OR: + t.expect(tok.LOGICAL_OR) + else: + break + + while len(exprs) > 1: + right = exprs.pop() + left = exprs[-1] + exprs[-1] = ParseNode(kind.OR, op.OR, + left.startpos, right.endpos, + None, [left, right]) + return exprs[0] + +def _conditional_expression(t, allowin): + kid = _logical_or_expression(t, allowin) + if t.peek().tok == tok.QUESTION: + t.expect(tok.QUESTION) + if_ = _assignment_expression(t, True) + t.expect(tok.COLON) + else_ = _assignment_expression(t, allowin) + return ParseNode(kind.HOOK, None, + kid.startpos, else_.endpos, + None, [kid, if_, else_]) + else: + return kid + +_ASSIGNS = { + tok.ASSIGN: (kind.ASSIGN, None), + tok.ASSIGN_URSHIFT: (kind.ASSIGN, op.URSH), + tok.ASSIGN_LSHIFT: (kind.ASSIGN, op.LSH), + tok.ASSIGN_RSHIFT: (kind.ASSIGN, op.RSH), + tok.ASSIGN_ADD: (kind.ASSIGN, op.ADD), + tok.ASSIGN_SUB: (kind.ASSIGN, op.SUB), + tok.ASSIGN_MUL: (kind.ASSIGN, op.MUL), + tok.ASSIGN_MOD: (kind.ASSIGN, op.MOD), + tok.ASSIGN_BIT_AND: (kind.ASSIGN, op.BITAND), + tok.ASSIGN_BIT_OR: (kind.ASSIGN, op.BITOR), + tok.ASSIGN_BIT_XOR: (kind.ASSIGN, op.BITXOR), + tok.ASSIGN_DIV: (kind.ASSIGN, op.DIV), +} +def _assignment_expression(t, allowin): + left = _conditional_expression(t, allowin) + if t.peek().tok in _ASSIGNS: + kid = left + while kid.kind == kind.RP: + kid, = kid.kids + if kid.kind == kind.NAME: + assert kid.opcode == op.NAME + kid.opcode = op.SETNAME + elif kid.kind == kind.DOT: + assert kid.opcode == op.GETPROP, left.op + kid.opcode = op.SETPROP + elif kid.kind == kind.LB: + assert kid.opcode == op.GETELEM + kid.opcode = op.SETELEM + elif kid.kind == kind.LP: + assert kid.opcode == op.CALL + kid.opcode = op.SETCALL + else: + raise JSSyntaxError(left.startpos, 'invalid_assign') + kind_, op_ = _ASSIGNS[t.peek().tok] + t.advance() + right = _assignment_expression(t, allowin) + return ParseNode(kind_, op_, + left.startpos, right.endpos, None, [left, right]) + else: + return left + +def _expression(t, allowin): + items = [] + items.append(_assignment_expression(t, allowin)) + while t.peek().tok == tok.COMMA: + t.advance() + items.append(_assignment_expression(t, allowin)) + if len(items) > 1: + return ParseNode(kind.COMMA, None, items[0].startpos, + items[-1].endpos, None, items) + else: + return items[0] + +def _variable_declaration(t, allowin): + nodes = [] + while True: + x = t.expect(tok.NAME) + value = None + if t.peek().tok == tok.ASSIGN: + t.advance() + value = _assignment_expression(t, allowin) + nodes.append(ParseNode(kind.NAME, op.SETNAME if value else op.NAME, + x.startpos, + value.endpos if value else x.endpos, + x.atom, [value])) + + if t.peek().tok == tok.COMMA: + t.advance() + else: + return nodes + +def _block_statement(t): + kids = [] + startpos = t.expect(tok.LBRACE).startpos + while t.peek().tok != tok.RBRACE: + kids.append(_statement(t)) + endpos = t.expect(tok.RBRACE).endpos + return ParseNode(kind.LC, None, startpos, endpos, None, kids) + +def _empty_statement(t): + # EMPTY STATEMENT + x = t.expect(tok.SEMI) + return ParseNode(kind.SEMI, None, x.startpos, x.endpos, None, [None]) + +def _var_statement(t): + # VARIABLE STATEMENT + startpos = t.expect(tok.VAR).startpos + nodes = _variable_declaration(t, True) + return _auto_semicolon(t, kind.VAR, op.DEFVAR, + startpos, nodes[-1].endpos, None, nodes) + +def _if_statement(t): + # IF STATEMENT + startpos = t.expect(tok.IF).startpos + t.expect(tok.LPAREN) + condition = _expression(t, True) + t.expect(tok.RPAREN) + if_body = _statement(t) + if t.peek().tok == tok.ELSE: + t.advance() + else_body = _statement(t) + else: + else_body = None + endpos = else_body.endpos if else_body else if_body.endpos + return ParseNode(kind.IF, None, startpos, + endpos, None, [condition, if_body, else_body]) + +def _do_statement(t): + startpos = t.expect(tok.DO).startpos + code = _statement(t) + t.expect(tok.WHILE) + t.expect(tok.LPAREN) + expr = _expression(t, True) + endtoken = t.expect(tok.RPAREN) + return _auto_semicolon(t, kind.DO, None, + startpos, endtoken.endpos, None, [code, expr]) + +def _while_statement(t): + startpos = t.expect(tok.WHILE).startpos + t.expect(tok.LPAREN) + expr = _expression(t, True) + t.expect(tok.RPAREN) + code = _statement(t) + return ParseNode(kind.WHILE, None, + startpos, code.endpos, None, [expr, code]) + +def _for_statement(t): + for_startpos = t.expect(tok.FOR).startpos + t.expect(tok.LPAREN) + + for_exprs = [] + if t.peek().tok == tok.VAR: + var_startpos = t.advance().startpos + kids = _variable_declaration(t, False) + vars = ParseNode(kind.VAR, op.DEFVAR, var_startpos, kids[-1].endpos, + None, kids) + + if t.peek().tok == tok.IN: + t.advance() + in_ = _expression(t, True) + for_exprs = [vars, in_] + else: + for_exprs = [vars, None, None] + else: + if t.peek().tok != tok.SEMI: + expr = _expression(t, False) + else: + expr = None + + if t.peek().tok == tok.IN: + t.advance() + vars = expr + in_ = _expression(t, True) + for_exprs = [vars, in_] + else: + for_exprs = [expr, None, None] + + if len(for_exprs) == 2: + condition = ParseNode(kind.IN, None, for_exprs[0].startpos, + for_exprs[-1].endpos, None, for_exprs) + else: + x = t.expect(tok.SEMI) + if t.peek().tok != tok.SEMI: + for_exprs[1] = _expression(t, True) + t.expect(tok.SEMI) + if t.peek().tok != tok.RPAREN: + for_exprs[2] = _expression(t, True) + condition = ParseNode(kind.RESERVED, None, None, None, + None, for_exprs) + + t.expect(tok.RPAREN) + body = _statement(t) + return ParseNode(kind.FOR, + op.FORIN if condition.kind == kind.IN else None, + for_startpos, body.endpos, + None, [condition, body]) + +def _continue_statement(t): + endtoken = t.expect(tok.CONTINUE) + startpos = endtoken.startpos + + if t.peek_sameline().tok == tok.NAME: + endtoken = t.expect(tok.NAME) + name = endtoken.atom + else: + name = None + # TODO: Validate Scope Labels + return _auto_semicolon(t, kind.CONTINUE, None, startpos, endtoken.endpos, name, []) + +def _break_statement(t): + endtoken = t.expect(tok.BREAK) + startpos = endtoken.startpos + + if t.peek_sameline().tok == tok.NAME: + endtoken = t.expect(tok.NAME) + name = endtoken.atom + else: + name = None + # TODO: Validate Scope Labels + return _auto_semicolon(t, kind.BREAK, None, startpos, endtoken.endpos, name, []) + +def _return_statement(t): + endtoken = t.expect(tok.RETURN) + startpos = endtoken.startpos + + if t.peek_sameline().tok not in (tok.EOF, tok.EOL, tok.SEMI): + expr = _expression(t, True) + endtoken = expr + else: + expr = None + # TODO: Validate Scope Labels + return _auto_semicolon(t, kind.RETURN, None, startpos, endtoken.endpos, + None, [expr]) + +def _with_statement(t): + startpos = t.expect(tok.WITH).startpos + t.expect(tok.LPAREN) + expr = _expression(t, True) + t.expect(tok.RPAREN) + body = _statement(t) + return ParseNode(kind.WITH, None, startpos, body.endpos, None, [expr, body]) + +def _switch_statement(t): + switch_startpos = t.expect(tok.SWITCH).startpos + t.expect(tok.LPAREN) + expr = _expression(t, True) + t.expect(tok.RPAREN) + lc_startpos = t.expect(tok.LBRACE).startpos + cases = [] + while t.peek().tok != tok.RBRACE: + case_kind = None + case_expr = None + if t.peek().tok == tok.CASE: + case_startpos = t.advance().startpos + case_kind = kind.CASE + case_expr = _expression(t, True) + elif t.peek().tok == tok.DEFAULT: + case_startpos = t.advance().startpos + case_kind = kind.DEFAULT + else: + raise JSSyntaxError(t.peek().startpos, 'invalid_case') + + case_endpos = t.expect(tok.COLON).endpos + + statements = [] + while t.peek().tok not in (tok.DEFAULT, tok.CASE, tok.RBRACE): + statements.append(_statement(t)) + if statements: + statements_startpos = statements[0].startpos + statements_endpos = statements[-1].endpos + case_endpos = statements[-1].endpos + else: + statements_startpos = case_endpos + statements_endpos = case_endpos + + cases.append(ParseNode(case_kind, None, case_startpos, case_endpos, + None, [ + case_expr, + ParseNode(kind.LC, None, statements_startpos, + statements_endpos, None, statements) + ])) + + rc_endpos = t.expect(tok.RBRACE).endpos + return ParseNode(kind.SWITCH, None, switch_startpos, rc_endpos, + None, [expr, + ParseNode(kind.LC, None, lc_startpos, rc_endpos, None, cases)]) + +def _throw_statement(t): + # TODO: Validate Scope + startpos = t.expect(tok.THROW).startpos + if t.peek_sameline().tok == tok.EOL: + raise JSSyntaxError(t.peek_sameline().startpos, 'expected_statement') + expr = _expression(t, True) + return _auto_semicolon(t, kind.THROW, op.THROW, startpos, expr.endpos, + None, [expr]) + +def _try_statement(t): + try_startpos = t.expect(tok.TRY).startpos + + try_node = _block_statement(t) + catch_node = None + finally_node = None + try_endpos = None + + if t.peek().tok == tok.CATCH: + catch_startpos = t.advance().startpos + t.expect(tok.LPAREN) + x = t.expect(tok.NAME) + catch_expr = ParseNode(kind.NAME, None, x.startpos, x.endpos, + x.atom, [None]) + t.expect(tok.RPAREN) + catch_block = _block_statement(t) + catch_endpos = catch_block.endpos + catch_node = \ + ParseNode(kind.RESERVED, None, None, None, None, [ + ParseNode(kind.LEXICALSCOPE, op.LEAVEBLOCK, + catch_startpos, catch_endpos, None, [ + ParseNode(kind.CATCH, None, catch_startpos, + catch_endpos, None, + [catch_expr, None, catch_block]) + ]) + ]) + try_endpos = catch_endpos + + if t.peek().tok == tok.FINALLY: + t.advance() + finally_node = _block_statement(t) + try_endpos = finally_node.endpos + + if not catch_node and not finally_node: + raise JSSyntaxError(try_endpos, 'invalid_catch') + + return ParseNode(kind.TRY, None, try_startpos, try_endpos, + None, + [try_node, catch_node, finally_node]) + +def _statement(t): + # TODO: Labelled Statement + x = t.peek() + if x.tok == tok.LBRACE: + return _block_statement(t) + elif x.tok == tok.SEMI: + return _empty_statement(t) + elif x.tok == tok.VAR: + return _var_statement(t) + elif x.tok == tok.IF: + return _if_statement(t) + elif x.tok == tok.DO: + return _do_statement(t) + elif x.tok == tok.WHILE: + return _while_statement(t) + elif x.tok == tok.FOR: + return _for_statement(t) + elif x.tok == tok.CONTINUE: + return _continue_statement(t) + elif x.tok == tok.BREAK: + return _break_statement(t) + elif x.tok == tok.RETURN: + return _return_statement(t) + elif x.tok == tok.WITH: + return _with_statement(t) + elif x.tok == tok.SWITCH: + return _switch_statement(t) + elif x.tok == tok.THROW: + return _throw_statement(t) + elif x.tok == tok.TRY: + return _try_statement(t) + elif x.tok == tok.EOF: + raise JSSyntaxError(x.startpos, 'eof') + elif x.tok == tok.FUNCTION: + return _function_declaration(t, op.CLOSURE) #TODO: warn, since this is not reliable + + elif x.tok not in (tok.LBRACE, tok.FUNCTION): + expr = _expression(t, True) + if expr.kind == tok.NAME and t.peek().tok == tok.COLON: + t.expect(tok.COLON) + stmt = _statement(t) + return ParseNode(kind.COLON, op.NAME, expr.startpos, + stmt.endpos, expr.atom, [stmt]) + + return _auto_semicolon(t, kind.SEMI, None, expr.startpos, expr.endpos, + None, [expr]) + else: + raise JSSyntaxError(x.startpos, 'syntax_error') + +def _sourceelements(t, end_tok): + nodes = [] + while True: + x = t.peek() + if x.tok == tok.FUNCTION: + nodes.append(_function_declaration(t, None)) + elif x.tok == end_tok: + return nodes + else: + nodes.append(_statement(t)) + +def parsestring(s, startpos=None): + stream = tokenizer.TokenStream(s, startpos) + t = tokenizer.Tokenizer(stream) + nodes = _sourceelements(t, tok.EOF) + lc_endpos = t.expect(tok.EOF).endpos + lc_startpos = nodes[-1].startpos if nodes else lc_endpos + return ParseNode(kind.LC, None, lc_startpos, lc_endpos, None, nodes) + +def is_valid_version(version): + return version in _VERSIONS + +def _validate(node, depth=0): + for kid in node.kids: + if kid: + assert kid.parent is node + _validate(kid, depth+1) + +def parse(script, jsversion, + error_callback, startpos): + # TODO: respect version + assert is_valid_version(jsversion) + try: + root = parsestring(script, startpos) + except JSSyntaxError as error: + error_callback(error.pos.line, error.pos.col, error.msg, error.msg_args) + return None + _validate(root) + return root + +def is_compilable_unit(script, jsversion): + # TODO: respect version + assert is_valid_version(jsversion) + try: + parsestring(script) + except JSSyntaxError as error: + return error.msg not in ('eof', 'unterminated_comment') + return True + +class TestParser(unittest.TestCase): + def testCompilableUnit(self): + self.assert_(is_compilable_unit('', 'default')) + self.assert_(is_compilable_unit('/**/', 'default')) + self.assert_(not is_compilable_unit('/*', 'default')) + def testUnterminatedComment(self): + try: + parsestring('/*') + except JSSyntaxError as error: + self.assertEqual(error.pos, NodePos(0,1)) + else: + self.assert_(False) + def testObjectEndComma(self): + root = parsestring('a={a:1,}') + node, = root.kids + self.assertEquals(node.kind, kind.SEMI) + node, = node.kids + self.assertEquals(node.kind, kind.ASSIGN) + left, right = node.kids + self.assertEquals(left.atom, 'a') + self.assertEquals(right.kind, kind.RC) + node = right.end_comma + self.assertEquals(node.kind, tok.COMMA) + self.assertEquals(node.startpos, NodePos(0, 6)) + self.assertEquals(node.endpos, NodePos(0, 6)) + def _testArrayEndComma(self, script, col): + root = parsestring(script) + node, = root.kids + self.assertEquals(node.kind, kind.SEMI) + node, = node.kids + self.assertEquals(node.kind, kind.ASSIGN) + left, right = node.kids + self.assertEquals(left.atom, 'a') + self.assertEquals(right.kind, kind.RB) + node = right.end_comma + self.assertEquals(node is None, col is None) + if col is None: + self.assert_(node is None) + else: + self.assertEquals(node.kind, tok.COMMA) + self.assertEquals(node.startpos, NodePos(0, col)) + self.assertEquals(node.endpos, NodePos(0, col)) + def testArrayEndComma(self): + self._testArrayEndComma('a=[,]', 3) + self._testArrayEndComma('a=[a,]', 4) + self._testArrayEndComma('a=[a,b,c]', None) + def _testArrayCommas(self, script, items, end_comma): + root = parsestring(script) + node, = root.kids + self.assertEquals(node.kind, kind.SEMI) + node, = node.kids + self.assertEquals(node.kind, kind.ASSIGN) + left, right = node.kids + self.assertEquals(left.atom, 'a') + self.assertEquals(right.kind, kind.RB) + node = right + self.assertEquals(len(node.kids), len(items)) + for kid, item in zip(node.kids, items): + self.assertEquals(kid.atom, item) + self.assertEquals(bool(node.end_comma), end_comma) + def testArrayCommas(self): + self._testArrayCommas('a=[]', [], False) + self._testArrayCommas('a=[,]', [None], True) + self._testArrayCommas('a=[,,]', [None, None], True) + self._testArrayCommas('a=[,1]', [None, '1'], False) + self._testArrayCommas('a=[,,1]', [None, None, '1'], False) + self._testArrayCommas('a=[1,,1]', ['1', None, '1'], False) + self._testArrayCommas('a=[,1,]', [None, '1'], True) + def testParseArray(self): + try: + parsestring('a=[1 1]') + except JSSyntaxError as error: + pass + else: + self.assert_(False) Added: trunk/jsengine/parser/_constants_kind.py =================================================================== --- trunk/jsengine/parser/_constants_kind.py (rev 0) +++ trunk/jsengine/parser/_constants_kind.py 2013-09-28 03:06:19 UTC (rev 304) @@ -0,0 +1,79 @@ +# vim: sw=4 ts=4 et + +_KINDS = [ + 'AND', + 'BITAND', + 'BITOR', + 'BITXOR', + 'CATCH', + 'COMMENT', + 'DELETE', + 'DIVOP', + 'DOT', + 'EQ', + 'FINALLY', + 'FUNCTION', + 'HOOK', + 'IF', + 'IN', + 'INC', + 'INSTANCEOF', + 'LB', + 'LC', + 'LEXICALSCOPE', + 'LP', + 'MINUS', + 'NAME', + 'NEW', + 'OBJECT', + 'OR', + 'PLUS', + 'PRIMARY', + 'RB', + 'RC', + 'RELOP', + 'RESERVED', + 'RP', + 'SEMI', + 'SHOP', + 'STAR', + 'TRY', + 'UNARYOP', + 'VAR', + 'ASSIGN', + 'CASE', + 'COLON', + 'DEFAULT', + 'EQOP', + 'OBJECT', + 'RELOP', + 'SWITCH', + 'WITH', + 'WHILE', + 'DO', + 'FOR', + 'COMMA', + 'DEC', + 'BREAK', + 'CONTINUE', + 'THROW', + 'RETURN', + 'UNARYOP', + 'LP', + 'NUMBER', + 'RB', + 'STRING', + 'YIELD', # TODO +] +class _Kind(str): + def __repr__(self): + return 'kind.%s' % self + +class _Kinds: + def __init__(self): + for kind in _KINDS: + setattr(self, kind, _Kind(kind)) + def contains(self, item): + return isinstance(item, _Kind) and \ + getattr(self, item) is item +kind = _Kinds() Added: trunk/jsengine/parser/_constants_op.py =================================================================== --- trunk/jsengine/parser/_constants_op.py (rev 0) +++ trunk/jsengine/parser/_constants_op.py 2013-09-28 03:06:19 UTC (rev 304) @@ -0,0 +1,85 @@ +# vim: sw=4 ts=4 et + +_OPS = [ + 'ADD', + 'AND', + 'ANONFUNOBJ', + 'ARGNAME', + 'BITAND', + 'BITNOT', + 'BITOR', + 'BITXOR', + 'CALL', + 'C_COMMENT', + 'CLOSURE', + 'CPP_COMMENT', + 'DECNAME', + 'DEFVAR', + 'DIV', + 'EQOP', + 'FALSE', + 'FORIN', + 'GETELEM', + 'GETPROP', + 'GT', + 'GE', + 'HOOK', + 'HTMLCOMMENT', + 'IN', + 'INCNAME', + 'INSTANCEOF', + 'LEAVEBLOCK', + 'LSH', + 'LT', + 'LE', + 'MOD', + 'MUL', + 'NAME', + 'NAMEDEC', + 'NAMEINC', + 'NAMEDFUNOBJ', + 'NEG', + 'NE', + 'NEW', + 'NEW_EQ', + 'NEW_NE', + 'NOT', + 'NULL', + 'NUMBER', + 'OR', + 'POS', + 'PROPINC', + 'REGEXP', + 'RSH', + 'SETCALL', + 'SETELEM', + 'SETNAME', + 'SETPROP', + 'STRING', + 'SUB', + 'THIS', + 'TRUE', + 'THROW', + 'TYPEOF', + 'URSH', + 'VOID', + 'EQ', + 'NAME', + 'REGEXP', + 'SETNAME', + 'VOID', + 'CALL', +] +class _Op(str): + def __repr__(self): + return 'op.%s' % self + +class _Ops: + NOP = None # TODO! + def __init__(self): + for op in _OPS: + setattr(self, op, _Op(op)) + def contains(self, item): + return isinstance(item, _Op) and \ + getattr(self, item) is item +op = _Ops() Added: trunk/jsengine/structs.py =================================================================== --- trunk/jsengine/structs.py (rev 0) +++ trunk/jsengine/structs.py 2013-09-28 03:06:19 UTC (rev 304) @@ -0,0 +1,196 @@ +# vim: ts=4 sw=4 expandtab +import bisect +import functools + +from parser._constants_kind import kind +from parser._constants_op import op + +class NodePositions: + " Given a string, allows [x] lookups for NodePos line and col... [truncated message content] |
From: <mat...@us...> - 2011-12-02 18:49:16
|
Revision: 303 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=303&view=rev Author: matthiasmiller Date: 2011-12-02 18:49:10 +0000 (Fri, 02 Dec 2011) Log Message: ----------- Fix --dump command line option. Modified Paths: -------------- trunk/javascriptlint/jsl.py Modified: trunk/javascriptlint/jsl.py =================================================================== --- trunk/javascriptlint/jsl.py 2011-04-07 00:07:05 UTC (rev 302) +++ trunk/javascriptlint/jsl.py 2011-12-02 18:49:10 UTC (rev 303) @@ -9,6 +9,7 @@ from optparse import OptionParser import conf +import fs import htmlparse import jsparse import lint @@ -21,7 +22,7 @@ def _dump(paths): for path in paths: - script = util.readfile(path) + script = fs.readfile(path) jsparse.dump_tree(script) def _lint(paths, conf_, printpaths): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2011-04-07 00:07:12
|
Revision: 302 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=302&view=rev Author: matthiasmiller Date: 2011-04-07 00:07:05 +0000 (Thu, 07 Apr 2011) Log Message: ----------- Move file system functions into separate module in preparation for online lint. Modified Paths: -------------- trunk/javascriptlint/conf.py trunk/javascriptlint/lint.py trunk/javascriptlint/util.py Added Paths: ----------- trunk/javascriptlint/fs.py Modified: trunk/javascriptlint/conf.py =================================================================== --- trunk/javascriptlint/conf.py 2010-10-03 20:18:10 UTC (rev 301) +++ trunk/javascriptlint/conf.py 2011-04-07 00:07:05 UTC (rev 302) @@ -2,6 +2,7 @@ import os import unittest +import fs import util import warnings @@ -186,7 +187,7 @@ def loadfile(self, path): path = os.path.abspath(path) - conf = open(path, 'r').read() + conf = fs.readfile(path) try: self.loadtext(conf, dir=os.path.dirname(path)) except ConfError, error: Added: trunk/javascriptlint/fs.py =================================================================== --- trunk/javascriptlint/fs.py (rev 0) +++ trunk/javascriptlint/fs.py 2011-04-07 00:07:05 UTC (rev 302) @@ -0,0 +1,17 @@ +# vim: ts=4 sw=4 expandtab +import codecs +import os + +def readfile(path): + file = codecs.open(path, 'r', 'utf-8') + contents = file.read() + if contents and contents[0] == unicode(codecs.BOM_UTF8, 'utf8'): + contents = contents[1:] + return contents + +def normpath(path): + path = os.path.abspath(path) + path = os.path.normcase(path) + path = os.path.normpath(path) + return path + Property changes on: trunk/javascriptlint/fs.py ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2010-10-03 20:18:10 UTC (rev 301) +++ trunk/javascriptlint/lint.py 2011-04-07 00:07:05 UTC (rev 302) @@ -4,6 +4,7 @@ import re import conf +import fs import htmlparse import jsparse import visitation @@ -295,12 +296,12 @@ def _lint_error(*args): return lint_error(normpath, *args) - normpath = util.normpath(path) + normpath = fs.normpath(path) if normpath in lint_cache: return lint_cache[normpath] if printpaths: print normpath - contents = util.readfile(path) + contents = fs.readfile(path) lint_cache[normpath] = _Script() script_parts = [] Modified: trunk/javascriptlint/util.py =================================================================== --- trunk/javascriptlint/util.py 2010-10-03 20:18:10 UTC (rev 301) +++ trunk/javascriptlint/util.py 2011-04-07 00:07:05 UTC (rev 302) @@ -1,6 +1,5 @@ # vim: ts=4 sw=4 expandtab import cgi -import codecs import os.path import re import unittest @@ -101,19 +100,6 @@ return re.sub(regexp, lambda match: replacements[match.group(0)], formatted_error) -def readfile(path): - file = codecs.open(path, 'r', 'utf-8') - contents = file.read() - if contents and contents[0] == unicode(codecs.BOM_UTF8, 'utf8'): - contents = contents[1:] - return contents - -def normpath(path): - path = os.path.abspath(path) - path = os.path.normcase(path) - path = os.path.normpath(path) - return path - class TestUtil(unittest.TestCase): def testIdentifier(self): assert not isidentifier('') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2010-10-03 20:18:17
|
Revision: 301 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=301&view=rev Author: matthiasmiller Date: 2010-10-03 20:18:10 +0000 (Sun, 03 Oct 2010) Log Message: ----------- Add support for content types and differing JavaScript versions. Modified Paths: -------------- trunk/javascriptlint/conf.py trunk/javascriptlint/jsparse.py trunk/javascriptlint/lint.py trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c trunk/javascriptlint/util.py trunk/javascriptlint/warnings.py Added Paths: ----------- trunk/tests/control_comments/conf-version-2.js trunk/tests/control_comments/conf-version.js trunk/tests/html/e4x.html trunk/tests/html/unsupported_version.html Modified: trunk/javascriptlint/conf.py =================================================================== --- trunk/javascriptlint/conf.py 2010-04-23 21:09:57 UTC (rev 300) +++ trunk/javascriptlint/conf.py 2010-10-03 20:18:10 UTC (rev 301) @@ -2,6 +2,7 @@ import os import unittest +import util import warnings def _getwarningsconf(): @@ -80,6 +81,11 @@ #+define document +### JavaScript Version +# To change the default JavaScript version: +#+default-type text/javascript;version=1.5 +#+default-type text/javascript;e4x=1 + ### Files # Specify which files to lint # Use "+recurse" to enable recursion (disabled by default). @@ -144,6 +150,17 @@ parm = os.path.join(dir, parm) self.value.append((self._recurse.value, parm)) +class JSVersionSetting(Setting): + wants_parm = True + value = util.JSVersion.default() + def load(self, enabled, parm): + if not enabled: + raise ConfError, 'Expected +.' + + self.value = util.JSVersion.fromtype(parm) + if not self.value: + raise ConfError, 'Invalid JavaScript version: %s' % parm + class Conf: def __init__(self): recurse = BooleanSetting(False) @@ -157,6 +174,7 @@ 'define': DeclareSetting(), 'context': BooleanSetting(True), 'process': ProcessSetting(recurse), + 'default-version': JSVersionSetting(), # SpiderMonkey warnings 'no_return_value': BooleanSetting(True), 'equal_as_assign': BooleanSetting(True), Modified: trunk/javascriptlint/jsparse.py =================================================================== --- trunk/javascriptlint/jsparse.py 2010-04-23 21:09:57 UTC (rev 300) +++ trunk/javascriptlint/jsparse.py 2010-10-03 20:18:10 UTC (rev 301) @@ -7,6 +7,7 @@ import spidermonkey from spidermonkey import tok, op +from util import JSVersion _tok_names = dict(zip( [getattr(tok, prop) for prop in dir(tok)], @@ -145,6 +146,11 @@ return True +def isvalidversion(jsversion): + if jsversion is None: + return True + return spidermonkey.is_valid_version(jsversion.version) + def findpossiblecomments(script, node_positions): pos = 0 single_line_re = r"//[^\r\n]*" @@ -193,7 +199,7 @@ # this one was within a string or a regexp. pos = match.start()+1 -def parse(script, error_callback, startpos=None): +def parse(script, jsversion, error_callback, startpos=None): """ All node positions will be relative to startpos. This allows scripts to be embedded in a file (for example, HTML). """ @@ -203,7 +209,10 @@ error_callback(line, col, msg) startpos = startpos or NodePos(0,0) - return spidermonkey.parse(script, _Node, _wrapped_callback, + jsversion = jsversion or JSVersion.default() + assert isvalidversion(jsversion) + return spidermonkey.parse(script, jsversion.version, jsversion.e4x, + _Node, _wrapped_callback, startpos.line, startpos.col) def filtercomments(possible_comments, node_positions, root_node): @@ -237,8 +246,10 @@ possible_comments = findpossiblecomments(script, node_positions) return filtercomments(possible_comments, node_positions, root_node) -def is_compilable_unit(script): - return spidermonkey.is_compilable_unit(script) +def is_compilable_unit(script, jsversion): + jsversion = jsversion or JSVersion.default() + assert isvalidversion(jsversion) + return spidermonkey.is_compilable_unit(script, jsversion.version, jsversion.e4x) def _dump_node(node, depth=0): if node is None: @@ -263,12 +274,12 @@ def dump_tree(script): def error_callback(line, col, msg): print '(%i, %i): %s', (line, col, msg) - node = parse(script, error_callback) + node = parse(script, None, error_callback) _dump_node(node) class TestComments(unittest.TestCase): def _test(self, script, expected_comments): - root = parse(script, lambda line, col, msg: None) + root = parse(script, None, lambda line, col, msg: None) comments = findcomments(script, root) encountered_comments = [node.atom for node in comments] self.assertEquals(encountered_comments, list(expected_comments)) @@ -365,10 +376,11 @@ ('re = /.*', False), ('{ // missing curly', False) ) - for text, result in tests: - self.assertEquals(is_compilable_unit(text), result) + for text, expected in tests: + encountered = is_compilable_unit(text, JSVersion.default()) + self.assertEquals(encountered, expected) # NOTE: This seems like a bug. - self.assert_(is_compilable_unit("/* test")) + self.assert_(is_compilable_unit("/* test", JSVersion.default())) class TestLineOffset(unittest.TestCase): def testErrorPos(self): @@ -376,7 +388,7 @@ errors = [] def onerror(line, col, msg): errors.append((line, col, msg)) - parse(script, onerror, startpos) + parse(script, None, onerror, startpos) self.assertEquals(len(errors), 1) return errors[0] self.assertEquals(geterror(' ?', None), (0, 1, 'syntax_error')) @@ -385,7 +397,7 @@ self.assertEquals(geterror('\n ?', NodePos(1,1)), (2, 1, 'syntax_error')) def testNodePos(self): def getnodepos(script, startpos): - root = parse(script, None, startpos) + root = parse(script, None, None, startpos) self.assertEquals(root.kind, tok.LC) var, = root.kids self.assertEquals(var.kind, tok.VAR) @@ -398,7 +410,7 @@ self.assertEquals(getnodepos('\n\n var x;', NodePos(3,4)), NodePos(5,1)) def testComments(self): def testcomment(comment, startpos, expectedpos): - root = parse(comment, None, startpos) + root = parse(comment, None, None, startpos) comment, = findcomments(comment, root, startpos) self.assertEquals(comment.start_pos(), expectedpos) for comment in ('/*comment*/', '//comment'): Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2010-04-23 21:09:57 UTC (rev 300) +++ trunk/javascriptlint/lint.py 2010-10-03 20:18:10 UTC (rev 301) @@ -63,6 +63,7 @@ 'pass': (False), 'declare': (True), 'unused': (True), + 'content-type': (True), } if control_comment.lower() in control_comments: keyword = control_comment.lower() @@ -240,19 +241,21 @@ if global_: return global_ -def _findhtmlscripts(contents): +def _findhtmlscripts(contents, default_version): starttag = None nodepos = jsparse.NodePositions(contents) for tag in htmlparse.findscripttags(contents): if tag['type'] == 'start': # Ignore nested start tags. if not starttag: - starttag = tag + jsversion = util.JSVersion.fromattr(tag['attr'], default_version) + starttag = dict(tag, jsversion=jsversion) src = tag['attr'].get('src') if src: yield { 'type': 'external', - 'src': src + 'jsversion': jsversion, + 'src': src, } elif tag['type'] == 'end': if not starttag: @@ -268,25 +271,27 @@ endoffset = nodepos.to_offset(endpos) script = contents[startoffset:endoffset] - if jsparse.is_compilable_unit(script): - starttag = None + if not jsparse.isvalidversion(starttag['jsversion']) or \ + jsparse.is_compilable_unit(script, starttag['jsversion']): if script.strip(): yield { 'type': 'inline', + 'jsversion': starttag['jsversion'], 'pos': startpos, 'contents': script, } + starttag = None else: assert False, 'Invalid internal tag type %s' % tag['type'] def lint_files(paths, lint_error, conf=conf.Conf(), printpaths=True): - def lint_file(path, kind): - def import_script(import_path): + def lint_file(path, kind, jsversion): + def import_script(import_path, jsversion): # The user can specify paths using backslashes (such as when # linting Windows scripts on a posix environment. import_path = import_path.replace('\\', os.sep) import_path = os.path.join(os.path.dirname(path), import_path) - return lint_file(import_path, 'js') + return lint_file(import_path, 'js', jsversion) def _lint_error(*args): return lint_error(normpath, *args) @@ -300,14 +305,20 @@ script_parts = [] if kind == 'js': - script_parts.append((None, contents)) + script_parts.append((None, jsversion or conf['default-version'], contents)) elif kind == 'html': - for script in _findhtmlscripts(contents): + assert jsversion is None + for script in _findhtmlscripts(contents, conf['default-version']): + # TODO: Warn about foreign languages. + if not script['jsversion']: + continue + if script['type'] == 'external': - other = import_script(script['src']) + other = import_script(script['src'], script['jsversion']) lint_cache[normpath].importscript(other) elif script['type'] == 'inline': - script_parts.append((script['pos'], script['contents'])) + script_parts.append((script['pos'], script['jsversion'], + script['contents'])) else: assert False, 'Invalid internal script type %s' % \ script['type'] @@ -321,12 +332,12 @@ for path in paths: ext = os.path.splitext(path)[1] if ext.lower() in ['.htm', '.html']: - lint_file(path, 'html') + lint_file(path, 'html', None) else: - lint_file(path, 'js') + lint_file(path, 'js', None) -def _lint_script_part(scriptpos, script, script_cache, conf, ignores, - report_native, report_lint, import_callback): +def _lint_script_part(scriptpos, jsversion, script, script_cache, conf, + ignores, report_native, report_lint, import_callback): def parse_error(row, col, msg): if not msg in ('anon_no_return_value', 'no_return_value', 'redeclared_var', 'var_hides_arg'): @@ -375,7 +386,28 @@ node_positions = jsparse.NodePositions(script, scriptpos) possible_comments = jsparse.findpossiblecomments(script, node_positions) - root = jsparse.parse(script, parse_error, scriptpos) + # Check control comments for the correct version. It may be this comment + # isn't a valid comment (for example, it might be inside a string literal) + # After parsing, validate that it's legitimate. + jsversionnode = None + for comment in possible_comments: + cc = _parse_control_comment(comment) + if cc: + node, keyword, parms = cc + if keyword == 'content-type': + ccversion = util.JSVersion.fromtype(parms) + if ccversion: + jsversion = ccversion + jsversionnode = node + else: + report(node, 'unsupported_version', version=parms) + + if not jsparse.isvalidversion(jsversion): + report_lint(jsversionnode, 'unsupported_version', scriptpos, + version=jsversion.version) + return + + root = jsparse.parse(script, jsversion, parse_error, scriptpos) if not root: # Report errors and quit. for pos, msg in parse_errors: @@ -383,6 +415,11 @@ return comments = jsparse.filtercomments(possible_comments, node_positions, root) + + if jsversionnode is not None and jsversionnode not in comments: + # TODO + report(jsversionnode, 'incorrect_version') + start_ignore = None for comment in comments: cc = _parse_control_comment(comment) @@ -461,7 +498,7 @@ # Process imports by copying global declarations into the universal scope. for path in import_paths: - script_cache.importscript(import_callback(path)) + script_cache.importscript(import_callback(path, jsversion)) for name, node in declares: declare_scope = script_cache.scope.find_scope(node) @@ -494,9 +531,9 @@ return lint_error(pos.line, pos.col, errname, errdesc) - for scriptpos, script in script_parts: + for scriptpos, jsversion, script in script_parts: ignores = [] - _lint_script_part(scriptpos, script, script_cache, conf, ignores, + _lint_script_part(scriptpos, jsversion, script, script_cache, conf, ignores, report_native, report_lint, import_callback) scope = script_cache.scope @@ -620,8 +657,55 @@ </html> """ scripts = [(x.get('src'), x.get('contents')) - for x in _findhtmlscripts(html)] + for x in _findhtmlscripts(html, util.JSVersion.default())] self.assertEquals(scripts, [ ('test.js', None), (None, "<!--\nvar s = '<script></script>';\n-->") ]) + def testJSVersion(self): + def parsetag(starttag, default_version=None): + script, = _findhtmlscripts(starttag + '/**/</script>', \ + default_version) + return script + + script = parsetag('<script>') + self.assertEquals(script['jsversion'], None) + + script = parsetag('<script language="vbscript">') + self.assertEquals(script['jsversion'], None) + + script = parsetag('<script type="text/javascript">') + self.assertEquals(script['jsversion'], util.JSVersion.default()) + + script = parsetag('<SCRIPT TYPE="TEXT/JAVASCRIPT">') + self.assertEquals(script['jsversion'], util.JSVersion.default()) + + script = parsetag('<script type="text/javascript; version = 1.6 ">') + self.assertEquals(script['jsversion'], util.JSVersion('1.6', False)) + + script = parsetag('<script type="text/javascript; version = 1.6 ">') + self.assertEquals(script['jsversion'], util.JSVersion('1.6', False)) + + script = parsetag('<SCRIPT TYPE="TEXT/JAVASCRIPT; e4x = 1 ">') + self.assertEquals(script['jsversion'], util.JSVersion('default', True)) + + script = parsetag('<script type="" language="livescript">') + self.assertEquals(script['jsversion'], util.JSVersion.default()) + + script = parsetag('<script type="" language="MOCHA">') + self.assertEquals(script['jsversion'], util.JSVersion.default()) + + script = parsetag('<script type="" language="JavaScript1.2">') + self.assertEquals(script['jsversion'], util.JSVersion('1.2', False)) + + script = parsetag('<script type="text/javascript;version=1.2" language="javascript1.4">') + self.assertEquals(script['jsversion'], util.JSVersion('1.2', False)) + + # Test setting the default version. + script = parsetag('<script>', util.JSVersion('1.2', False)) + self.assertEquals(script['jsversion'], util.JSVersion('1.2', False)) + + script = parsetag('<script type="" language="mocha">', + util.JSVersion('1.2', False)) + self.assertEquals(script['jsversion'], util.JSVersion.default()) + Modified: trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c =================================================================== --- trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c 2010-04-23 21:09:57 UTC (rev 300) +++ trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c 2010-10-03 20:18:10 UTC (rev 301) @@ -70,6 +70,9 @@ static PyObject* is_compilable_unit(PyObject *self, PyObject *args); +static PyObject* +is_valid_version(PyObject *self, PyObject *args); + static PyMethodDef module_methods[] = { {"parse", module_parse, METH_VARARGS, "Parses \"script\" and returns a tree of \"node_class\"."}, @@ -77,6 +80,9 @@ {"is_compilable_unit", is_compilable_unit, METH_VARARGS, "Returns True if \"script\" is a compilable unit."}, + {"is_valid_version", is_valid_version, METH_VARARGS, + "Returns True if \"strversion\" is a valid version."}, + {NULL, NULL, 0, NULL} /* Sentinel */ }; @@ -398,13 +404,22 @@ /* Returns NULL on success. Otherwise, it returns an error. * If the error is blank, an exception will be set. */ -static const char* create_jscontext(void* ctx_data, +static const char* create_jscontext(const char* strversion, PyObject* is_e4x, + void* ctx_data, JSRuntime** runtime, JSContext** context, JSObject** global) { + JSVersion jsversion; + + jsversion = JS_StringToVersion(strversion); + if (jsversion == JSVERSION_UNKNOWN) { + PyErr_SetString(PyExc_ValueError, "\"version\" is invalid"); + return ""; + } + *runtime = JS_NewRuntime(8L * 1024L * 1024L); if (*runtime == NULL) - return"cannot create runtime"; + return "cannot create runtime"; *context = JS_NewContext(*runtime, 8192); if (*context == NULL) @@ -413,6 +428,11 @@ JS_SetErrorReporter(*context, error_reporter); JS_SetContextPrivate(*context, ctx_data); JS_ToggleOptions(*context, JSOPTION_STRICT); + if (is_e4x == Py_True) + JS_ToggleOptions(*context, JSOPTION_XML); + else if (is_e4x != Py_False) + return "e4x is not a boolean"; + JS_SetVersion(*context, jsversion); *global = JS_NewObject(*context, NULL, NULL, NULL); if (*global == NULL) @@ -430,6 +450,8 @@ struct { char* scriptbuf; int scriptbuflen; + const char* jsversion; + PyObject* is_e4x; PyObject* pynode; JSRuntime* runtime; @@ -446,8 +468,9 @@ error = "encountered an unknown error"; /* validate arguments */ - if (!PyArg_ParseTuple(args, "es#OOll", "utf16", &m.scriptbuf, - &m.scriptbuflen, &m.ctx_data.node_class, &m.ctx_data.error_callback, + if (!PyArg_ParseTuple(args, "es#sO!OOll", "utf16", &m.scriptbuf, + &m.scriptbuflen, &m.jsversion, &PyBool_Type, &m.is_e4x, + &m.ctx_data.node_class, &m.ctx_data.error_callback, &m.ctx_data.first_lineno, &m.ctx_data.first_index)) { return NULL; } @@ -462,7 +485,8 @@ return NULL; } - error = create_jscontext(&m.ctx_data, &m.runtime, &m.context, &m.global); + error = create_jscontext(m.jsversion, m.is_e4x, &m.ctx_data, + &m.runtime, &m.context, &m.global); if (error) goto cleanup; @@ -511,6 +535,8 @@ struct { char* scriptbuf; int scriptbuflen; + const char* jsversion; + PyObject* is_e4x; JSRuntime* runtime; JSContext* context; JSObject* global; @@ -521,10 +547,13 @@ memset(&m, 0, sizeof(m)); error = "encountered an unknown error"; - if (!PyArg_ParseTuple(args, "es#", "utf16", &m.scriptbuf, &m.scriptbuflen)) + if (!PyArg_ParseTuple(args, "es#sO!", "utf16", &m.scriptbuf, + &m.scriptbuflen, &m.jsversion, &PyBool_Type, &m.is_e4x)) { return NULL; + } - error = create_jscontext(NULL, &m.runtime, &m.context, &m.global); + error = create_jscontext(m.jsversion, m.is_e4x, NULL, + &m.runtime, &m.context, &m.global); if (error) goto cleanup; @@ -546,13 +575,22 @@ PyErr_SetString(PyExc_StandardError, error); return NULL; } - if (m.is_compilable) { - Py_INCREF(Py_True); - return Py_True; - } - else { - Py_INCREF(Py_False); - return Py_False; - } + if (m.is_compilable) + Py_RETURN_TRUE; + else + Py_RETURN_FALSE; } +static PyObject* +is_valid_version(PyObject *self, PyObject *args) { + const char* strversion = NULL; + + if (!PyArg_ParseTuple(args, "s", &strversion)) + return NULL; + + if (JS_StringToVersion(strversion) != JSVERSION_UNKNOWN) + Py_RETURN_TRUE; + else + Py_RETURN_FALSE; +} + Modified: trunk/javascriptlint/util.py =================================================================== --- trunk/javascriptlint/util.py 2010-04-23 21:09:57 UTC (rev 300) +++ trunk/javascriptlint/util.py 2010-10-03 20:18:10 UTC (rev 301) @@ -1,4 +1,5 @@ # vim: ts=4 sw=4 expandtab +import cgi import codecs import os.path import re @@ -6,6 +7,57 @@ _identifier = re.compile('^[A-Za-z_$][A-Za-z0-9_$]*$') +_contenttypes = ( + 'text/javascript', + 'text/ecmascript', + 'application/javascript', + 'application/ecmascript', + 'application/x-javascript', +) + +class JSVersion: + def __init__(self, jsversion, is_e4x): + self.version = jsversion + self.e4x = is_e4x + + def __eq__(self, other): + return self.version == other.version and \ + self.e4x == other.e4x + + @classmethod + def default(klass): + return klass('default', False) + + @classmethod + def fromattr(klass, attr, default_version=None): + if attr.get('type'): + return klass.fromtype(attr['type']) + if attr.get('language'): + return klass.fromlanguage(attr['language']) + return default_version + + @classmethod + def fromtype(klass, type_): + typestr, typeparms = cgi.parse_header(type_) + if typestr.lower() in _contenttypes: + jsversion = typeparms.get('version', 'default') + is_e4x = typeparms.get('e4x') == '1' + return klass(jsversion, is_e4x) + return None + + @classmethod + def fromlanguage(klass, language): + if language.lower() in ('javascript', 'livescript', 'mocha'): + return klass.default() + + # Simplistic parsing of javascript/x.y + if language.lower().startswith('javascript'): + language = language[len('javascript'):] + if language.replace('.', '').isdigit(): + return klass(language, False) + + return None + def isidentifier(text): return _identifier.match(text) @@ -91,7 +143,6 @@ self.assertEquals(format_error('encode:__ERROR_MSGENC__', r'c:\my\file', 1, 2, 'name', r'a\b'), r'a\\b') - if __name__ == '__main__': unittest.main() Modified: trunk/javascriptlint/warnings.py =================================================================== --- trunk/javascriptlint/warnings.py 2010-04-23 21:09:57 UTC (rev 300) +++ trunk/javascriptlint/warnings.py 2010-10-03 20:18:10 UTC (rev 301) @@ -94,7 +94,9 @@ 'invalid_pass': 'unexpected "pass" control comment', 'want_assign_or_call': 'expected an assignment or function call', 'no_return_value': 'function {name} does not always return a value', - 'anon_no_return_value': 'anonymous function does not always return value' + 'anon_no_return_value': 'anonymous function does not always return value', + 'unsupported_version': 'JavaScript {version} is not supported', + 'incorrect_version': 'Expected /*jsl:content-type*/ control comment. The script was parsed with the wrong version.', } def format_error(errname, **errargs): @@ -511,6 +513,8 @@ # NOTE: Don't handle comma-separated statements. if child.kind in (tok.ASSIGN, tok.INC, tok.DEC, tok.DELETE, tok.COMMA): return + if child.kind == tok.YIELD: + return # Ignore function calls. if child.kind == tok.LP and child.opcode == op.CALL: return Added: trunk/tests/control_comments/conf-version-2.js =================================================================== --- trunk/tests/control_comments/conf-version-2.js (rev 0) +++ trunk/tests/control_comments/conf-version-2.js 2010-10-03 20:18:10 UTC (rev 301) @@ -0,0 +1,7 @@ +/*conf:+default-version text/javascript;version=1.7*/ +/*jsl:content-type text/javascript;version=1.6*/ + +/* Make sure that the control comment overrides the config file. */ +function default_version() { + yield true; /*warning:semi_before_stmnt*/ +} Added: trunk/tests/control_comments/conf-version.js =================================================================== --- trunk/tests/control_comments/conf-version.js (rev 0) +++ trunk/tests/control_comments/conf-version.js 2010-10-03 20:18:10 UTC (rev 301) @@ -0,0 +1,4 @@ +/*conf:+default-version text/javascript;version=1.7*/ +function default_version() { + yield true; +} Added: trunk/tests/html/e4x.html =================================================================== --- trunk/tests/html/e4x.html (rev 0) +++ trunk/tests/html/e4x.html 2010-10-03 20:18:10 UTC (rev 301) @@ -0,0 +1,28 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> +<html> +<head> + <title>JavaScript Lint Test Page</title> + <!-- If e4x is disabled, HTML commments are treated as + comment-till-end-of-line. --> + <script type="text/javascript"> + // e4x is disabled by default, so HTML comments are single-line only. + var comment_a = <!-- + ? /*warning:syntax_error*/ + -->; + </script> + <script type="text/javascript;e4x=1"> + // Explicitly enable e4x. + var comment_c = <!-- + ? + -->; + </script> + <script type="text/javascript;version=1.6;e4x=0"> + // e4x is always enabled in 1.6+ + var comment_b = <!-- + ? + -->; + </script> +</head> +<body> +</body> +</html> Added: trunk/tests/html/unsupported_version.html =================================================================== --- trunk/tests/html/unsupported_version.html (rev 0) +++ trunk/tests/html/unsupported_version.html 2010-10-03 20:18:10 UTC (rev 301) @@ -0,0 +1,19 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> +<html> +<head> + <title>JavaScript Lint Test Page</title> + <script type="text/javascript;version=0.1"> /*warning:unsupported_version*/ + function x() { + return 10; + } + </script> + <script language="javascript10.0"> /*warning:unsupported_version*/ + function x() { + return 10; + } + </script> +</head> +<body> +</body> +</html> + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2010-04-23 21:10:04
|
Revision: 300 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=300&view=rev Author: matthiasmiller Date: 2010-04-23 21:09:57 +0000 (Fri, 23 Apr 2010) Log Message: ----------- Fix invalid exit code. Modified Paths: -------------- trunk/javascriptlint/jsl.py Modified: trunk/javascriptlint/jsl.py =================================================================== --- trunk/javascriptlint/jsl.py 2010-04-23 20:58:11 UTC (rev 299) +++ trunk/javascriptlint/jsl.py 2010-04-23 21:09:57 UTC (rev 300) @@ -149,7 +149,7 @@ sys.exit(3) if _lint_results['warnings']: sys.exit(1) - sys.exit(1) + sys.exit(0) if __name__ == '__main__': main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2010-04-23 20:58:18
|
Revision: 299 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=299&view=rev Author: matthiasmiller Date: 2010-04-23 20:58:11 +0000 (Fri, 23 Apr 2010) Log Message: ----------- Add /*jsl:unused <identifier>*/ control comment. Modified Paths: -------------- trunk/javascriptlint/lint.py trunk/tests/warnings/unreferenced_identifier.js Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2010-04-23 20:38:04 UTC (rev 298) +++ trunk/javascriptlint/lint.py 2010-04-23 20:58:11 UTC (rev 299) @@ -61,7 +61,8 @@ 'import': (True), 'fallthru': (False), 'pass': (False), - 'declare': (True) + 'declare': (True), + 'unused': (True), } if control_comment.lower() in control_comments: keyword = control_comment.lower() @@ -82,6 +83,7 @@ self._kids = [] self._identifiers = {} self._references = [] + self._unused = [] self._node = None def add_scope(self, node): assert not node is None @@ -98,6 +100,8 @@ } def add_reference(self, name, node): self._references.append((name, node)) + def set_unused(self, name, node): + self._unused.append((name, node)) def get_identifier(self, name): if name in self._identifiers: return self._identifiers[name]['node'] @@ -183,6 +187,14 @@ if not is_in_with_scope: undeclared.append((self, name, node)) + # Remove all variables that have been set as "unused". + for name, node in self._unused: + resolved = self.resolve_identifier(name) + if resolved: + unreferenced.pop((resolved[0], name), None) + else: + undeclared.append((self, name, node)) + for child in self._kids: child._find_warnings(unreferenced, undeclared, obstructive, is_in_with_scope) @@ -355,6 +367,7 @@ parse_errors = [] declares = [] + unused_identifiers = [] import_paths = [] fallthrus = [] passes = [] @@ -380,6 +393,11 @@ report(node, 'jsl_cc_not_understood') else: declares.append((parms, node)) + elif keyword == 'unused': + if not util.isidentifier(parms): + report(node, 'jsl_cc_not_understood') + else: + unused_identifiers.append((parms, node)) elif keyword == 'ignore': if start_ignore: report(node, 'mismatch_ctrl_comments') @@ -449,6 +467,10 @@ declare_scope = script_cache.scope.find_scope(node) _warn_or_declare(declare_scope, name, 'var', node, report) + for name, node in unused_identifiers: + unused_scope = script_cache.scope.find_scope(node) + unused_scope.set_unused(name, node) + def _lint_script_parts(script_parts, script_cache, lint_error, conf, import_callback): def report_lint(node, errname, pos=None, **errargs): errdesc = warnings.format_error(errname, **errargs) Modified: trunk/tests/warnings/unreferenced_identifier.js =================================================================== --- trunk/tests/warnings/unreferenced_identifier.js 2010-04-23 20:38:04 UTC (rev 298) +++ trunk/tests/warnings/unreferenced_identifier.js 2010-04-23 20:58:11 UTC (rev 299) @@ -84,5 +84,19 @@ return parm; }; } + + function test_unused(parm) { /*warning:unreferenced_function*/ + /*jsl:unused parm*/ + /*jsl:unused bogus_outer*/ /*warning:undeclared_identifier*/ + + var unused_var; + /*jsl:unused unused_var*/ + + with (parm) { /*warning:with_statement*/ + /*jsl:unused bogus_inner*/ /*warning:undeclared_identifier*/ + x = 42; + } + } + return get_callback(42); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2010-04-23 20:38:12
|
Revision: 298 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=298&view=rev Author: matthiasmiller Date: 2010-04-23 20:38:04 +0000 (Fri, 23 Apr 2010) Log Message: ----------- Add options to control whether to show header, file listings, and lint summary. Modified Paths: -------------- trunk/javascriptlint/jsl.py trunk/javascriptlint/lint.py Modified: trunk/javascriptlint/jsl.py =================================================================== --- trunk/javascriptlint/jsl.py 2010-04-23 20:09:47 UTC (rev 297) +++ trunk/javascriptlint/jsl.py 2010-04-23 20:38:04 UTC (rev 298) @@ -24,12 +24,12 @@ script = util.readfile(path) jsparse.dump_tree(script) -def _lint(paths, conf_): +def _lint(paths, conf_, printpaths): def lint_error(path, line, col, errname, errdesc): _lint_results['warnings'] = _lint_results['warnings'] + 1 print util.format_error(conf_['output-format'], path, line, col, errname, errdesc) - lint.lint_files(paths, lint_error, conf=conf_) + lint.lint_files(paths, lint_error, conf=conf_, printpaths=printpaths) def _resolve_paths(path, recurse): # Build a list of directories @@ -46,6 +46,11 @@ # force an error to be thrown if no matching files were found. return paths or [path] +def printlogo(): + # TODO: Print version number. + print "JavaScript Lint" + print "Developed by Matthias Miller (http://www.JavaScriptLint.com)" + def _profile_enabled(func, *args, **kwargs): import tempfile import hotshot @@ -83,6 +88,12 @@ help="minimal output") add("--verbose", dest="verbosity", action="store_const", const=2, help="verbose output") + add("--nologo", dest="printlogo", action="store_false", default=True, + help="suppress version information") + add("--nofilelisting", dest="printlisting", action="store_false", + default=True, help="suppress file names") + add("--nosummary", dest="printsummary", action="store_false", default=True, + help="suppress lint summary") add("--help:conf", dest="showdefaultconf", action="store_true", default=False, help="display the default configuration file") parser.set_defaults(verbosity=1) @@ -96,6 +107,9 @@ print conf.DEFAULT_CONF sys.exit() + if options.printlogo: + printlogo() + conf_ = conf.Conf() if options.conf: conf_.loadfile(options.conf) @@ -125,8 +139,12 @@ if options.dump: profile_func(_dump, paths) else: - profile_func(_lint, paths, conf_) + profile_func(_lint, paths, conf_, options.printlisting) + if options.printsummary: + print '\n%i error(s), %i warnings(s)' % (_lint_results['errors'], + _lint_results['warnings']) + if _lint_results['errors']: sys.exit(3) if _lint_results['warnings']: Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2010-04-23 20:09:47 UTC (rev 297) +++ trunk/javascriptlint/lint.py 2010-04-23 20:38:04 UTC (rev 298) @@ -267,7 +267,7 @@ else: assert False, 'Invalid internal tag type %s' % tag['type'] -def lint_files(paths, lint_error, conf=conf.Conf()): +def lint_files(paths, lint_error, conf=conf.Conf(), printpaths=True): def lint_file(path, kind): def import_script(import_path): # The user can specify paths using backslashes (such as when @@ -281,7 +281,8 @@ normpath = util.normpath(path) if normpath in lint_cache: return lint_cache[normpath] - print normpath + if printpaths: + print normpath contents = util.readfile(path) lint_cache[normpath] = _Script() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2010-04-23 20:09:53
|
Revision: 297 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=297&view=rev Author: matthiasmiller Date: 2010-04-23 20:09:47 +0000 (Fri, 23 Apr 2010) Log Message: ----------- Fix indentation. Modified Paths: -------------- trunk/tests/warnings/want_assign_or_call.js Modified: trunk/tests/warnings/want_assign_or_call.js =================================================================== --- trunk/tests/warnings/want_assign_or_call.js 2010-04-23 20:05:58 UTC (rev 296) +++ trunk/tests/warnings/want_assign_or_call.js 2010-04-23 20:09:47 UTC (rev 297) @@ -24,7 +24,7 @@ /* Test with arguments to the constructor. */ new function(x) { - this.x = x; + this.x = x; }(42); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2010-04-23 20:06:04
|
Revision: 296 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=296&view=rev Author: matthiasmiller Date: 2010-04-23 20:05:58 +0000 (Fri, 23 Apr 2010) Log Message: ----------- Fix exception when passing arguments to a "new function() {};" statement. Modified Paths: -------------- trunk/javascriptlint/warnings.py trunk/tests/warnings/want_assign_or_call.js Modified: trunk/javascriptlint/warnings.py =================================================================== --- trunk/javascriptlint/warnings.py 2010-04-19 15:19:43 UTC (rev 295) +++ trunk/javascriptlint/warnings.py 2010-04-23 20:05:58 UTC (rev 296) @@ -516,7 +516,8 @@ return # Allow new function() { } as statements. if child.kind == tok.NEW: - grandchild, = child.kids + # The first kid is the constructor, followed by its arguments. + grandchild = child.kids[0] if grandchild.kind == tok.FUNCTION: return raise LintWarning, child Modified: trunk/tests/warnings/want_assign_or_call.js =================================================================== --- trunk/tests/warnings/want_assign_or_call.js 2010-04-19 15:19:43 UTC (rev 295) +++ trunk/tests/warnings/want_assign_or_call.js 2010-04-23 20:05:58 UTC (rev 296) @@ -21,5 +21,10 @@ delete a; a.b(); + + /* Test with arguments to the constructor. */ + new function(x) { + this.x = x; + }(42); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2010-04-19 15:19:49
|
Revision: 295 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=295&view=rev Author: matthiasmiller Date: 2010-04-19 15:19:43 +0000 (Mon, 19 Apr 2010) Log Message: ----------- Fixes for Windows build. Modified Paths: -------------- trunk/javascriptlint/lint.py trunk/javascriptlint/visitation.py trunk/setup.py Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2009-12-16 17:23:22 UTC (rev 294) +++ trunk/javascriptlint/lint.py 2010-04-19 15:19:43 UTC (rev 295) @@ -531,7 +531,9 @@ scopes = [scope] class scope_checks: - ' ' + """ This is a non-standard visitation class to track scopes. The + docstring is unused since this class never throws lint errors. + """ @visitation.visit('push', tok.NAME) def _name(self, node): if node.node_index == 0 and node.parent.kind == tok.COLON and node.parent.parent.kind == tok.RC: Modified: trunk/javascriptlint/visitation.py =================================================================== --- trunk/javascriptlint/visitation.py 2009-12-16 17:23:22 UTC (rev 294) +++ trunk/javascriptlint/visitation.py 2010-04-19 15:19:43 UTC (rev 295) @@ -29,7 +29,7 @@ if klass.__name__.lower() != klass.__name__: raise ValueError, 'class names must be lowercase' if not klass.__doc__: - raise ValueError, 'missing docstring on class' + raise ValueError, 'missing docstring on class %s' % klass.__name__ # Look for functions with the "_visit_nodes" property. visitor = klass() Modified: trunk/setup.py =================================================================== --- trunk/setup.py 2009-12-16 17:23:22 UTC (rev 294) +++ trunk/setup.py 2010-04-19 15:19:43 UTC (rev 295) @@ -107,7 +107,7 @@ 'py2exe': { 'excludes': ['javascriptlint.spidermonkey_'], 'bundle_files': 1, - 'optimize': 2, + 'optimize': 1, # requires 1 to preserve docstrings } }, zipfile = None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2009-12-16 17:23:32
|
Revision: 294 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=294&view=rev Author: matthiasmiller Date: 2009-12-16 17:23:22 +0000 (Wed, 16 Dec 2009) Log Message: ----------- Embed the revision number in Windows executables. Also, add a config file to build on Windows 7. Modified Paths: -------------- trunk/setup.py Added Paths: ----------- trunk/spidermonkey/src/config/WINNT6.1.mk Modified: trunk/setup.py =================================================================== --- trunk/setup.py 2009-11-18 12:19:50 UTC (rev 293) +++ trunk/setup.py 2009-12-16 17:23:22 UTC (rev 294) @@ -10,6 +10,16 @@ class _BuildError(Exception): pass +def _getrevnum(): + path = os.path.dirname(os.path.abspath(__file__)) + p = subprocess.Popen(['svnversion', path], stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + if p.returncode != 0: + raise _BuildError, 'Error running svnversion: %s' % stderr + version = stdout.strip().rstrip('M') + return int(version) + def _runmakefiles(distutils_dir, build_opt=1, target=None): args = ['BUILD_OPT=%i' % build_opt] if distutils_dir: @@ -67,12 +77,12 @@ args = {} args.update( name = 'javascriptlint', - version = '1.0', + version = '0.0.0.%i' % _getrevnum(), author = 'Matthias Miller', author_email = 'in...@ja...', url = 'http://www.javascriptlint.com/', cmdclass = cmdclass, - description = 'JavaScript Lint', + description = 'JavaScript Lint (pyjsl beta r%i)' % _getrevnum(), ext_modules = [pyspidermonkey], packages = ['javascriptlint'], scripts = ['jsl'] Added: trunk/spidermonkey/src/config/WINNT6.1.mk =================================================================== --- trunk/spidermonkey/src/config/WINNT6.1.mk (rev 0) +++ trunk/spidermonkey/src/config/WINNT6.1.mk 2009-12-16 17:23:22 UTC (rev 294) @@ -0,0 +1 @@ +include $(DEPTH)/config/WINNT5.2.mk This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2009-11-18 12:20:04
|
Revision: 293 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=293&view=rev Author: matthiasmiller Date: 2009-11-18 12:19:50 +0000 (Wed, 18 Nov 2009) Log Message: ----------- #2891908: Fix exception when using finally without catch. Patch submitted on tracker. Modified Paths: -------------- trunk/javascriptlint/warnings.py Added Paths: ----------- trunk/tests/bugs/sf-2891908-finally_without_catch.js Modified: trunk/javascriptlint/warnings.py =================================================================== --- trunk/javascriptlint/warnings.py 2009-11-18 12:15:40 UTC (rev 292) +++ trunk/javascriptlint/warnings.py 2009-11-18 12:19:50 UTC (rev 293) @@ -193,15 +193,19 @@ elif node.kind == tok.TRY: try_, catch_, finally_ = node.kids - assert catch_.kind == tok.RESERVED - catch_, = catch_.kids - assert catch_.kind == tok.LEXICALSCOPE - catch_, = catch_.kids - assert catch_.kind == tok.CATCH - ignored, ignored, catch_ = catch_.kids - assert catch_.kind == tok.LC + exit_points = _get_exit_points(try_) - exit_points = _get_exit_points(try_) | _get_exit_points(catch_) + if catch_: + assert catch_.kind == tok.RESERVED + catch_, = catch_.kids + assert catch_.kind == tok.LEXICALSCOPE + catch_, = catch_.kids + assert catch_.kind == tok.CATCH + ignored, ignored, catch_ = catch_.kids + assert catch_.kind == tok.LC + + exit_points |= _get_exit_points(catch_) + if finally_: finally_exit_points = _get_exit_points(finally_) if None in finally_exit_points: Added: trunk/tests/bugs/sf-2891908-finally_without_catch.js =================================================================== --- trunk/tests/bugs/sf-2891908-finally_without_catch.js (rev 0) +++ trunk/tests/bugs/sf-2891908-finally_without_catch.js 2009-11-18 12:19:50 UTC (rev 293) @@ -0,0 +1,8 @@ +function f() { + try { + /*jsl:pass*/ + } + finally { + /*jsl:pass*/ + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2009-11-18 12:18:35
|
Revision: 292 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=292&view=rev Author: matthiasmiller Date: 2009-11-18 12:15:40 +0000 (Wed, 18 Nov 2009) Log Message: ----------- #2890901: Include missing test case. Added Paths: ----------- trunk/tests/bugs/sf-2890901-unicode.js Added: trunk/tests/bugs/sf-2890901-unicode.js =================================================================== --- trunk/tests/bugs/sf-2890901-unicode.js (rev 0) +++ trunk/tests/bugs/sf-2890901-unicode.js 2009-11-18 12:15:40 UTC (rev 292) @@ -0,0 +1,4 @@ +function unicode() { + return 'ö'; +} + Property changes on: trunk/tests/bugs/sf-2890901-unicode.js ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2009-11-18 12:07:08
|
Revision: 291 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=291&view=rev Author: matthiasmiller Date: 2009-11-18 12:06:56 +0000 (Wed, 18 Nov 2009) Log Message: ----------- #2890901: Support Unicode characters in scripts. Modified Paths: -------------- trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c trunk/spidermonkey/src/jsapi.c trunk/spidermonkey/src/jsapi.h Added Paths: ----------- trunk/tests/bugs/ Modified: trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c =================================================================== --- trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c 2009-11-18 11:11:00 UTC (rev 290) +++ trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c 2009-11-18 12:06:56 UTC (rev 291) @@ -19,7 +19,6 @@ #define ARRAY_COUNT(a) (sizeof(a) / sizeof(a[0])) - /** CONSTANTS */ static const char* tokens[] = { @@ -47,7 +46,21 @@ #define TOK_TO_NUM(tok) (tok+1000) #define OPCODE_TO_NUM(op) (op+2000) +static jschar* +tojschar(const char* buf) { + return (jschar*)buf; +} +static int +tojscharlen(int buflen) { + /* The buffer length shouldn't be an odd number, buf if it is, the buffer + will be truncated to exclude it. + */ + JS_STATIC_ASSERT(sizeof(char) == 1); + JS_STATIC_ASSERT(sizeof(jschar) == 2); + return buflen / 2; +} + /** MODULE INITIALIZATION */ @@ -415,7 +428,8 @@ static PyObject* module_parse(PyObject *self, PyObject *args) { struct { - const char* script; + char* scriptbuf; + int scriptbuflen; PyObject* pynode; JSRuntime* runtime; @@ -423,7 +437,6 @@ JSObject* global; JSTokenStream* token_stream; JSParseNode* jsnode; - JSString* contents; JSContextData ctx_data; } m; @@ -433,9 +446,9 @@ error = "encountered an unknown error"; /* validate arguments */ - if (!PyArg_ParseTuple(args, "sOOll", &m.script, &m.ctx_data.node_class, - &m.ctx_data.error_callback, &m.ctx_data.first_lineno, - &m.ctx_data.first_index)) { + if (!PyArg_ParseTuple(args, "es#OOll", "utf16", &m.scriptbuf, + &m.scriptbuflen, &m.ctx_data.node_class, &m.ctx_data.error_callback, + &m.ctx_data.first_lineno, &m.ctx_data.first_index)) { return NULL; } @@ -453,13 +466,8 @@ if (error) goto cleanup; - m.contents = JS_NewStringCopyZ(m.context, m.script); - if (m.contents == NULL) { - error = "cannot create script contents"; - goto cleanup; - } - - m.token_stream = js_NewBufferTokenStream(m.context, JS_GetStringChars(m.contents), JS_GetStringLength(m.contents)); + m.token_stream = js_NewBufferTokenStream(m.context, tojschar(m.scriptbuf), + tojscharlen(m.scriptbuflen)); if (!m.token_stream) { error = "cannot create token stream"; goto cleanup; @@ -486,6 +494,8 @@ JS_DestroyContext(m.context); if (m.runtime) JS_DestroyRuntime(m.runtime); + if (m.scriptbuf) + PyMem_Free(m.scriptbuf); if (error) { if (*error) { @@ -499,7 +509,8 @@ static PyObject* is_compilable_unit(PyObject *self, PyObject *args) { struct { - const char* script; + char* scriptbuf; + int scriptbuflen; JSRuntime* runtime; JSContext* context; JSObject* global; @@ -510,15 +521,16 @@ memset(&m, 0, sizeof(m)); error = "encountered an unknown error"; - if (!PyArg_ParseTuple(args, "s", &m.script)) + if (!PyArg_ParseTuple(args, "es#", "utf16", &m.scriptbuf, &m.scriptbuflen)) return NULL; error = create_jscontext(NULL, &m.runtime, &m.context, &m.global); if (error) goto cleanup; - m.is_compilable = JS_BufferIsCompilableUnit(m.context, m.global, - m.script, strlen(m.script)); + m.is_compilable = JS_UCBufferIsCompilableUnit(m.context, m.global, + tojschar(m.scriptbuf), + tojscharlen(m.scriptbuflen)); error = NULL; cleanup: @@ -526,6 +538,8 @@ JS_DestroyContext(m.context); if (m.runtime) JS_DestroyRuntime(m.runtime); + if (m.scriptbuf) + PyMem_Free(m.scriptbuf); if (error) { if (*error) Modified: trunk/spidermonkey/src/jsapi.c =================================================================== --- trunk/spidermonkey/src/jsapi.c 2009-11-18 11:11:00 UTC (rev 290) +++ trunk/spidermonkey/src/jsapi.c 2009-11-18 12:06:56 UTC (rev 291) @@ -3877,15 +3877,28 @@ { jschar *chars; JSBool result; + + CHECK_REQUEST(cx); + chars = js_InflateString(cx, bytes, &length); + if (!chars) + return JS_TRUE; + + result = JS_UCBufferIsCompilableUnit(cx, obj, chars, length); + JS_free(cx, chars); + return result; +} + +JS_PUBLIC_API(JSBool) +JS_UCBufferIsCompilableUnit(JSContext *cx, JSObject *obj, + const jschar *chars, size_t length) +{ + JSBool result; JSExceptionState *exnState; void *tempMark; JSTokenStream *ts; JSErrorReporter older; CHECK_REQUEST(cx); - chars = js_InflateString(cx, bytes, &length); - if (!chars) - return JS_TRUE; /* * Return true on any out-of-memory error, so our caller doesn't try to @@ -3912,7 +3925,6 @@ JS_ARENA_RELEASE(&cx->tempPool, tempMark); } - JS_free(cx, chars); JS_RestoreExceptionState(cx, exnState); return result; } Modified: trunk/spidermonkey/src/jsapi.h =================================================================== --- trunk/spidermonkey/src/jsapi.h 2009-11-18 11:11:00 UTC (rev 290) +++ trunk/spidermonkey/src/jsapi.h 2009-11-18 12:06:56 UTC (rev 291) @@ -1606,6 +1606,10 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, const char *bytes, size_t length); +JS_PUBLIC_API(JSBool) +JS_UCBufferIsCompilableUnit(JSContext *cx, JSObject *obj, + const jschar *chars, size_t length); + /* * The JSScript objects returned by the following functions refer to string and * other kinds of literals, including doubles and RegExp objects. These This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2009-11-18 11:11:18
|
Revision: 290 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=290&view=rev Author: matthiasmiller Date: 2009-11-18 11:11:00 +0000 (Wed, 18 Nov 2009) Log Message: ----------- Refactor the handling of wilcards on the command line. Modified Paths: -------------- trunk/javascriptlint/jsl.py Modified: trunk/javascriptlint/jsl.py =================================================================== --- trunk/javascriptlint/jsl.py 2009-10-29 06:48:30 UTC (rev 289) +++ trunk/javascriptlint/jsl.py 2009-11-18 11:11:00 UTC (rev 290) @@ -1,6 +1,7 @@ #!/usr/bin/python # vim: ts=4 sw=4 expandtab import codecs +import fnmatch import glob import os import sys @@ -31,27 +32,20 @@ lint.lint_files(paths, lint_error, conf=conf_) def _resolve_paths(path, recurse): - if os.path.isfile(path): - return [path] - elif os.path.isdir(path): - dir = path - pattern = '*' - else: - dir, pattern = os.path.split(path) - # Build a list of directories - dirs = [dir] - if recurse: - for cur_root, cur_dirs, cur_files in os.walk(dir): - for name in cur_dirs: - dirs.append(os.path.join(cur_root, name)) - - # Glob all files. paths = [] - for dir in dirs: - paths.extend(glob.glob(os.path.join(dir, pattern))) - return paths + dir, pattern = os.path.split(path) + for cur_root, cur_dirs, cur_files in os.walk(dir): + paths.extend(os.path.join(cur_root, file) for file in \ + fnmatch.filter(cur_files, pattern)) + if not recurse: + break + + # If no files have been found, return the original path/pattern. This will + # force an error to be thrown if no matching files were found. + return paths or [path] + def _profile_enabled(func, *args, **kwargs): import tempfile import hotshot @@ -73,6 +67,14 @@ help="set the conf file") add("--profile", dest="profile", action="store_true", default=False, help="turn on hotshot profiling") + add("--recurse", dest="recurse", action="store_true", default=False, + help="recursively search directories on the command line") + if os.name == 'nt': + add("--disable-wildcards", dest="wildcards", action="store_false", + default=True, help="do not resolve wildcards in the command line") + else: + add("--enable-wildcards", dest="wildcards", action="store_true", + default=False, help="resolve wildcards in the command line") add("--dump", dest="dump", action="store_true", default=False, help="dump this script") add("--unittest", dest="unittest", action="store_true", default=False, @@ -114,7 +116,12 @@ for recurse, path in conf_['paths']: paths.extend(_resolve_paths(path, recurse)) for arg in args: - paths.extend(_resolve_paths(arg, False)) + if options.wildcards: + paths.extend(_resolve_paths(arg, options.recurse)) + elif options.recurse and os.path.isdir(arg): + paths.extend(_resolve_paths(os.path.join(arg, '*'), True)) + else: + paths.append(arg) if options.dump: profile_func(_dump, paths) else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2009-10-29 06:48:55
|
Revision: 289 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=289&view=rev Author: matthiasmiller Date: 2009-10-29 06:48:30 +0000 (Thu, 29 Oct 2009) Log Message: ----------- Fix build on Linux. Modified Paths: -------------- trunk/setup.py Modified: trunk/setup.py =================================================================== --- trunk/setup.py 2009-10-26 02:46:37 UTC (rev 288) +++ trunk/setup.py 2009-10-29 06:48:30 UTC (rev 289) @@ -19,8 +19,11 @@ # First build SpiderMonkey. Force it to link statically against the CRT to # make deployment easier. + if os.name == 'nt': + args.append('XCFLAGS=-MT') + ret = subprocess.call(['make', '-f', 'Makefile.ref', '-C', - 'spidermonkey/src', 'XCFLAGS=-MT'] + args) + 'spidermonkey/src'] + args) if ret != 0: raise _BuildError, 'Error running make.' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2009-10-26 02:46:47
|
Revision: 288 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=288&view=rev Author: matthiasmiller Date: 2009-10-26 02:46:37 +0000 (Mon, 26 Oct 2009) Log Message: ----------- Augment the py2exe build to run the executable through upx. Modified Paths: -------------- trunk/setup.py Modified: trunk/setup.py =================================================================== --- trunk/setup.py 2009-10-22 15:39:55 UTC (rev 287) +++ trunk/setup.py 2009-10-26 02:46:37 UTC (rev 288) @@ -7,7 +7,7 @@ import subprocess import sys -class _MakefileError(Exception): +class _BuildError(Exception): pass def _runmakefiles(distutils_dir, build_opt=1, target=None): @@ -22,12 +22,12 @@ ret = subprocess.call(['make', '-f', 'Makefile.ref', '-C', 'spidermonkey/src', 'XCFLAGS=-MT'] + args) if ret != 0: - raise _MakefileError, 'Error running make.' + raise _BuildError, 'Error running make.' # Then copy the files to the build directory. ret = subprocess.call(['make', '-f', 'Makefile.SpiderMonkey'] + args) if ret != 0: - raise _MakefileError, 'Error running make.' + raise _BuildError, 'Error running make.' class _MyBuild(distutils.command.build.build): def run(self): @@ -79,12 +79,22 @@ except ImportError: pass else: + class _MyPy2Exe(py2exe.build_exe.py2exe): + def run(self): + py2exe.build_exe.py2exe.run(self) + for exe in self.console_exe_files: + ret = subprocess.call(['upx', '-9', exe]) + if ret != 0: + raise _BuildError, 'Error running upx on %s' % exe + args['cmdclass']['py2exe'] = _MyPy2Exe + args.update( console = ['jsl'], options = { 'py2exe': { 'excludes': ['javascriptlint.spidermonkey_'], - 'bundle_files': 1 + 'bundle_files': 1, + 'optimize': 2, } }, zipfile = None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |