Repository: emacs-typescript/typescript.el
Branch: master
Commit: 2535780bdb31
Files: 18
Total size: 337.5 KB
Directory structure:
gitextract_b8dm76p3/
├── .github/
│ └── workflows/
│ └── build.yml
├── .gitignore
├── Dockerfile
├── Eask
├── LICENSE
├── Makefile
├── README.md
├── test-files/
│ ├── indentation-reference-document.ts
│ ├── list-items-indent-comma-first.ts
│ ├── list-items-indent-default.ts
│ ├── switch-case-indent-default.ts
│ └── switch-case-indent-disabled.ts
├── typescript-mode-general-tests.el
├── typescript-mode-jsdoc-tests.el
├── typescript-mode-lexical-binding-tests.el
├── typescript-mode-test-utilities.el
├── typescript-mode-tests.el
└── typescript-mode.el
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/workflows/build.yml
================================================
name: Build & Test
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
experimental: [false]
emacs-version: [26.3, 27.2, 28.2, 29.4, 30.2]
include:
- emacs-version: snapshot
experimental: true
os: ubuntu-latest
- emacs-version: snapshot
experimental: true
os: windows-latest
continue-on-error: ${{ matrix.experimental }}
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v6
- uses: jcs090218/setup-emacs@master
with:
version: ${{ matrix.emacs-version }}
- uses: emacs-eask/setup-eask@master
with:
version: 'snapshot'
- name: Run a multi-line script
run: |
emacs --version
make build
make test
================================================
FILE: .gitignore
================================================
# Created by https://www.gitignore.io/api/emacs,windows,linux
### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# eask packages
.eask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
# directory configuration
.dir-locals.el
### Linux ###
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/emacs,windows,linux
# ELPA-generated files.
/typescript-mode-autoloads.el
/typescript-mode-pkg.el
================================================
FILE: Dockerfile
================================================
FROM ubuntu:bionic
RUN apt-get update && \
apt-get install -y \
make curl python git emacs
RUN curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python
ENV PATH="/root/.cask/bin:${PATH}"
RUN mkdir -p /typescript-mode
COPY . /typescript-mode
WORKDIR /typescript-mode
CMD ["make", "test"]
================================================
FILE: Eask
================================================
(package "typescript-mode"
"0.4"
"Major mode for editing typescript")
(website-url "http://github.com/ananthakumaran/typescript.el")
(keywords "typescript" "languages")
(package-file "typescript-mode.el")
(files "*.el")
(source "gnu")
(source "melpa")
(depends-on "emacs" "24.3")
(setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432
================================================
FILE: LICENSE
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
================================================
FILE: Makefile
================================================
EMACS ?= emacs
EASK ?= eask
ELS = \
typescript-mode.el \
typescript-mode-test-utilities.el \
typescript-mode-general-tests.el \
typescript-mode-jsdoc-tests.el \
typescript-mode-tests.el
ELCS = $(ELS:.el=.elc)
clean:
rm -f $(ELCS)
build: clean
$(EASK) compile
test:
+ $(EMACS) -Q -batch -L . -l typescript-mode-tests.el -f ert-run-tests-batch-and-exit
# end
================================================
FILE: README.md
================================================
# typescript.el

[](https://melpa.org/#/typescript-mode)
[](https://stable.melpa.org/#/typescript-mode)
`typescript.el` is a major-mode for editing [Typescript](http://www.typescriptlang.org/)-files in [GNU Emacs](https://www.gnu.org/software/emacs/).
`typescript.el` is a self-contained, lightweight and minimalist major-mode
focused on providing basic font-lock/syntax-highlighting and
indentation for Typescript syntax, without any external dependencies.
Output from `tsc` and `tslint` is also handled seamlessly through
`compilation-mode`.
## A short note on development HALT
As the both the JavaScript and TypeScript languages have evolved to become ever more complex, so has the
Elisp codebase for `typescript-mode` trying to correctly handle them.
We've been at the point for quite some time where it has become increasingly obvious that the current code-base
simply cannot continue growing. It will be slow. It will be complex. It will be buggy. It will be head-ache inducing
to wrap our heads around it, and ... I guess we're already there.
Apart from occasional PRs getting merged, the current `typescript-mode` code isn't being developed because almost nobody
wants to work code of this complexity.
*Essentially all major development of `typescript-mode` has come to a halt.*
## Good news though!
Emacs 29 will ship with support for a parser-library called tree-sitter, and will actually have in-tree
support for TypeScript! So now you can just use the provided `typescript-ts-mode` and get
better support for TypeScript than `typescript.el` ever provided. This new mode also supports TSX.
Development of TypeScript-support will from now on continue in Emacs core, rather than this repo.
We hope you'll like the new experience.
# Installation
`typescript.el` can be installed from source directly using your
favourite approach or framework, or from MELPA and MELPA Stable as a
package.
To install typescript.el simply type `M-x package-installtypescript-mode`.
# Customization
To customize `typescript.el` just type the following: `M-x customize-grouptypescript`.
You can add any other customization you like to `typescript-mode-hook`
in your `init.el` file. `typescript.el` also handles `prog-mode-hook`
on versions of Emacs which supports it.
# Support for Compilation Mode
This mode automatically adds support for `compilation-mode` so that if
you run `M-x compiletsc` the error messages are correctly
parsed.
However, the error messages produced by `tsc` when its `pretty` flag
is turned on include ANSI color escapes, which by default
`compilation-mode` does not interpret. In order to get the escapes
parsed, you can use:
```elisp
(require 'ansi-color)
(defun colorize-compilation-buffer ()
(ansi-color-apply-on-region compilation-filter-start (point-max)))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
```
Or, if you prefer, you can configure `tsc` with the `pretty` flag set
to `false`: `tsc --pretty false`. However, doing this does more than
just turning off the colors. It also causes `tsc` to produce less
elaborate error messages.
# Contributing
To run the tests you can run `make test`.
If you prefer, you may run the tests via the provided `Dockerfile`.
```bash
docker build -t typescript-mode .
docker run --rm -v $(pwd):/typescript-mode typescript-mode
```
# Other Typescript-packages of interest
While `typescript.el` may *not* provide a full kitchen-sink, the good
news is that there's other packages which do!
More advanced features can be provided by using these additional
packages:
* [lsp-mode](https://github.com/emacs-lsp/lsp-mode) - A standards-based
code-completion and refactoring backend, based on the
[Language Server Protocol (LSP)](https://langserver.org/).
* [tide](https://github.com/ananthakumaran/tide/) - TypeScript
Interactive Development Environment for Emacs
* [ts-comint](https://github.com/josteink/ts-comint) - a Typescript REPL
in Emacs.
Initializing these with `typescript.el` will then become a matter of
creating your own `typescript-mode-hook` in your `init.el` file.
================================================
FILE: test-files/indentation-reference-document.ts
================================================
///
///
///
// used in fs.writeSync
/* tslint:disable:no-null-keyword */
/*
* this file is a butchered copy of TypeScript's tsserver.ts file
* made to contain the most important syntactical elements
* of TypeScript to verify indentation-code.
*
* It will not build, and that's NOT a problem!
*/
// namespaces indent.
namespace ts.server {
const net: {
connect(options: { port: number }, onConnect?: () => void): NodeSocket
} = require("net");
// functions indent.
function getGlobalTypingsCacheLocation() {
const obj = {
case: 1,
default: 2
};
}
// interfaces and classes indent.
interface NodeChildProcess {
send(message: any, sendHandle?: any): void;
on(message: "message" | "exit", f: (m: any) => void): void;
kill(): void;
pid: number;
}
export type SomeType = string | number;
class Logger implements ts.server.Logger {
private firstInGroup = true;
// parameter-lists are currently not indented like tsserver wants it to...
// constructor(private readonly logFilename: string,
// private readonly traceToConsole: boolean,
// private readonly level: LogLevel) {
// }
// function-typed class-members indent.
constructor(private readonly logFilename: string) {
console.log("yes");
}
static padStringRight(str: string, padding: string) {
return (str + padding).slice(0, padding.length);
}
close() {
if (this.fd >= 0) {
fs.close(this.fd);
}
}
}
// object initialization/parameter-lists indent.
const ioSession = new IOSession(
sys,
cancellationToken,
eventPort,
/*canUseEvents*/ eventPort === undefined,
useSingleInferredProject,
disableAutomaticTypingAcquisition,
getGlobalTypingsCacheLocation(),
telemetryEnabled,
logger);
process.on("uncaughtException", function (err: Error) {
ioSession.logError(err, "unknown");
});
// Generators as methods.
class WithAGeneratorFirst {
*blah() {
}
}
class WithAGeneratorAfterAProperty {
public foo: string = "1";
*blah() {
}
}
class WithAGeneratorAfterAnotherMethod {
foo() {
}
*blah() {
}
}
class WithSpaceAfterAsterisk {
bar() {
}
* oops() {
}
}
class WithSpaceAfterParens {
bar() {
}
*oops () {
}
}
class WithArguments {
bar() {
}
*oops(foo: number, bar: string) {
}
}
// Some continued expressions
{
const a = 1 *
2 /
3 +
4 -
5 %
6;
const b = 1 >
2;
const c = 1 <
2;
const d = 1 &
2 |
3;
const e = b ?
2 :
3;
const e2 = b ?
{ a: 1 } :
3;
const f = window
.document;
const g = f
instanceof Object;
const h = "q"
in [1, 2];
}
{
// Object with fields that are keyword names.
const a = {
in: 1,
IN: 1,
instanceof: 1,
instanceOf: 1,
};
// Objects with methods that are keyword names. At the top of
// the object declaration, and after a function declaration.
class One {
instanceOf(): void {
}
in(): void {}
}
// After a field declaration.
class Two {
foo: boolean = true;
instanceOf(): void {
}
}
}
// Spread syntax
{
const a = { a: 1, b: 2 };
const b = {
...a,
a: 3,
};
const c = [1, 2];
const d = [
"a",
...c
];
function foo(a: string,
b: number,
...rest: any[]) {
}
}
{
// Regular expressions in lists.
// List objects...
const a = [
/abc/,
/def/
];
const z =
/abcd/;
// Argument lists...
function foo(a: RegExp, b: RegExp): void {
}
foo(
/abc/,
/def/);
}
}
// Tests for return value annotations.
// Unannotated.
function moo(x: any,
f: string) {
return null;
}
// No parens around return type.
function moo2(x: any,
f: string): (a: number) => void {
return null;
}
// Parens around return type.
function foo(x: any,
f: string): ((a: number) => void) {
return null;
}
class Moo {}
// Type guard.
function foo2(x: any,
f: string): x is Moo {
return x.something === 1;
}
// Usage of generic in return type.
function foo3(a: number,
b: number): Array void>> {
return [];
}
// Curly brackets in return type.
function bar(a: number,
b: number): { z(): string } {
return {
z() { return "a"; }
};
}
// The sequence ): in the return type.
function bif(a: number,
b: number): "abc):d" {
return "abc):d";
}
// Generic and union in return type. This case was constructed from
// a specific bug in the indentation code.
function bif2(a: number,
b: number): Array | number {
return 1;
}
// Array shorthand.
function bif3(a: number,
b: number): number[] {
return [1];
}
// Array shorthand in union.
function bif4(a: number,
b: number): number[] | number {
return [1];
}
// Array shorthand in union, with spaces.
function bif5(a: number,
b: number): number[ ] | number {
return [1];
}
// Comment where the return type would appear.
function gogo(a: number,
b: number) /* foo */ {
}
// Function call in the list of arguments.
function foo5(x: any,
f: string = bif(1, 2)): ((a: number) => void) {
return null;
}
// Dotted name in return type.
function foo6(x: any,
f: number): ts.server.SomeType {
return "string";
}
// First parameter has function signature.
function foo7(x: (a: string, b: string) => Array,
b: number): void {
}
// Second parameter has function signature.
function foo7b(a: string,
x: (a: number, b: number) => Array): void {
}
function foo8(): void {
// Arrow function in first parameter.
foo7((a: string): Array => {
return [1];
},
1);
// Arrow function in first parameter, line break in parameters.
foo7((a: string,
b: string): Array => {
return [1];
},
1);
// Arrow function in second parameter.
foo7b("1",
(a: number, b: number): Array => {
return [1];
});
// Arrow function in second parameter, line break in parameters.
foo7b("1",
(a: number,
b: number): Array => {
return [1];
});
}
// Arrow function assignment, line break in parameters.
const foo9 = (a: string,
b: string): Array => {
return [1];
}
// Arrow function assignment.
const foo10 = (a: string, b: string): Array => {
return [1];
}
// Arrow function assignment, parenthesized.
const foo11 = ((a: string, b: string): Array => {
return [1];
});
function foo12(): void {
// Function in first parameter.
foo7(function (a: string): Array {
return [1];
},
1);
// Function in first parameter, line break in parameters.
foo7(function (a: string,
b: string): Array {
return [1];
},
1);
// Arrow function in second parameter.
foo7b("1",
function (a: number, b: number): Array {
return [1];
});
// Arrow function in second parameter, line break in parameters.
foo7b("1",
function (a: number,
b: number): Array {
return [1];
});
// Same cases as above but named.
// Function in first parameter.
foo7(function _mip(a: string): Array {
return [1];
},
1);
// Function in first parameter, line break in parameters.
foo7(function _mip(a: string,
b: string): Array {
return [1];
},
1);
// Arrow function in second parameter.
foo7b("1",
function _mip(a: number, b: number): Array {
return [1];
});
// Arrow function in second parameter, line break in parameters.
foo7b("1",
function _mip(a: number,
b: number): Array {
return [1];
});
// Same cases as above but generators.
// Function in first parameter.
foo7(function *(a: string): Array {
return [1];
},
1);
// Function in first parameter, line break in parameters.
foo7(function *(a: string,
b: string): Array {
return [1];
},
1);
// Arrow function in second parameter.
foo7b("1",
function *(a: number, b: number): Array {
return [1];
});
// Arrow function in second parameter, line break in parameters.
foo7b("1",
function *(a: number,
b: number): Array {
return [1];
});
// Check that JavaScript objects are still handled right. Whether
// in the 1st or subsequent position of a call.
function smurf(a: {}, b: {}) {}
smurf({
a: {},
},
{
a: {},
});
smurf({
a: {},
}, {
a: {},
});
}
// Number literals in the return type annotation.
function foo13(something: string,
somethingElse: string): 0b1 | 0 | -1 | 0o2 | 0x3f {
return 0;
}
// No spaces between numbers and type union symbols. (Also changed the
// notation to uppercase where possible.)
function foo14(something: string,
somethingElse: string): 0B1|0|-1|0O2|0X3F {
return 0;
}
const a =
1; // Blah
const b = 2;
function blipblop(): void {
{
const q = 1;
}
}
// The following section deals with distinguishing the purpose of the symbol >
// when it appears at the end of a line.
// cf. https://github.com/ananthakumaran/typescript.el/issues/81
{
var a, b, c, d, e, f, l, o, t, x, z
type z = {} // Zero argument
type o = {} // One argument
type t = {} // Two arguments
// greater-than operator
x = b >
c
// looks like a but is greater-than operator
x = t < z , z >
f()
// looks almost the same but this time, it's a type
type x = t < z , z >
f()
// looks almost the same but this time, it's a type
x = a as t < z , z >
f()
// tricky, this is greater-than, because "number" is a keyword
a = b as number < z , z >
f()
// Next one is ambiguous! It could be read as:
// (b as t) < z, z > f()
// or
// b as (t < z , z >) \n f()
// It turns out that when t is not a keyword, TypeScript always chooses the
// latter, and complains if you attempted the former
a = b as t < z , z >
f()
l = [
// operator at end of line
a >
b,
// operator alone on line
a
>
b,
// end of 1st line is type argument, 2nd is operator
a as b < c , d >
>
d
]
// properly-closed parameterized type, followed by operator
g = a as o < z > >
b
// Good case
class Q {
q: string = "a"
}
type a =
Q
const blah = 1
// Problem cases
interface Something {
a: string;
b: string;
c: -5;
}
class Fluff {
}
// Example of = and - in a type parameter.
type c
= Fluff
const moo = 1
// Example of + in a type parameter.
type d
= Fluff
const moo2 = 1
class Foo {
a : O
public readonly a : O
public b : O
private c : O
private d : O
}
type Foo {
readonly a : O
b : O
readonly b : O
c : { }
d : O
}
interface Foo {
a : O
b : { }
}
a = a ? a < a : a >
a
a = a ? a : a < a || a >
a
a = a ? a < a : a >
a
// ^ This test is the same as two above, but a bad guess could answer differently.
type Foo { }
a = a ? a < a : a >
a
class Foo { }
a = a ? a < a : a >
a
type A = B
foo
type A = import('../file').B
foo
}
container.each(x => x)
something() // No reason for this to be indented! (cf. issue #83)
// Method calls that look like braceless keywords should not indent!
function test() {
return (
f.catch()
)
return (
f.do()
)
return (
f.each()
)
return (
f.else()
)
return (
f.if()
)
return (
f.finally()
)
return (
f.then()
)
}
// https://github.com/emacs-typescript/typescript.el/issues/107
let $img: JQuery
if (variable != null) {
//
}
let $img2: JQuery = null
if (variable != null) {
//
}
// The following block deals with strings of member expressions on so-called
// "fluent" APIs.
interface Fnord {
log(...args: any[]): this;
blah(): this;
}
let fnord: Fnord = {} as any;
{
fnord
.log("sdf")
.blah();
const m =
fnord
.log()
.blah();
const b = { q: 1, f: 2}
const x =
fnord
.log({ a: b.q, z: b.f })
.blah();
(async () => {
const x = (
await (fnord as any)
.log(1));
})();
}
fnord
.log("sdf")
.blah();
const m =
fnord
.log()
.blah();
fnord
.log("sdf")
const q =
fnord
.log();
// This is a continued expression in parentheses.
const blip999 = (window.location.href === "fnord" ?
"a" :
"b");
// The following case is purposely not correct TS code. It tests against an
// infinite loop that would occur when the mode was asked to indent such
// incorrect syntax.
if (true) {
.bleh();
}
const m =
fnord()
.log()
.blah();
// This next expression is purposely not correct TS code. The missing parens
// after fnord would trigger an infinite loop in earlier implementations.
const m =
fnord
.log()
.blah();
) {
1 + 2; // Indenting this line would cause an infinite loop
}
================================================
FILE: test-files/list-items-indent-comma-first.ts
================================================
const arr =
[ 'one'
, 'two'
, 'three' ];
const obj =
{ a: 111
, b: 222
, c: 333 };
const depth = { arr: [ 'one'
, 'two'
, 'three' ]
, obj: { a: 111
, b: 222
, c: 333 }
, func_call: Object.assign
( {}
, { x: 1
, y: 2
, z: 3 }
, { i: 'i', j: 'j' } ) };
================================================
FILE: test-files/list-items-indent-default.ts
================================================
const arr =
[ 'one'
, 'two'
, 'three' ];
const obj =
{ a: 111
, b: 222
, c: 333 };
const depth = { arr: [ 'one'
, 'two'
, 'three' ]
, obj: { a: 111
, b: 222
, c: 333 }
, func_call: Object.assign
( {}
, { x: 1
, y: 2
, z: 3 }
, { i: 'i', j: 'j' } ) };
================================================
FILE: test-files/switch-case-indent-default.ts
================================================
function indentTest(): any {
const obj = {
case: 1,
default: 2
};
// This function was specifically added to test for a reversion in
// the code that indents switch statements.
function turnip(): void {
}
switch (process.platform) {
case "moo":
break;
case "win32": {
const basePath = process.env.LOCALAPPDATA ||
process.env.APPDATA;
return combinePaths(normalizeSlashes(basePath), "Microsoft/TypeScript");
}
case "darwin":
const objCase = {
case: 1,
default: 2
};
case "linux":
case "android": {
const cacheLocation = getNonWindowsCacheLocation(process.platform === "darwin");
return combinePaths(cacheLocation, "typescript");
}
default:
const objDefault = {
case: 1,
default: 2
};
Debug.fail(`unsupported platform '${process.platform}'`);
return;
}
}
================================================
FILE: test-files/switch-case-indent-disabled.ts
================================================
function getGlobalTypingsCacheLocation() {
const obj = {
case: 1,
default: 2
};
switch (process.platform) {
case "win32": {
const basePath = process.env.LOCALAPPDATA ||
process.env.APPDATA;
return combinePaths(normalizeSlashes(basePath), "Microsoft/TypeScript");
}
case "darwin":
const objCase = {
case: 1,
default: 2
};
case "linux":
case "android": {
const cacheLocation = getNonWindowsCacheLocation(process.platform === "darwin");
return combinePaths(cacheLocation, "typescript");
}
default:
const objDefault = {
case: 1,
default: 2
};
Debug.fail(`unsupported platform '${process.platform}'`);
return;
}
}
================================================
FILE: typescript-mode-general-tests.el
================================================
;;; typescript-mode-general-tests --- This file contains general tests for typescript-mode.el
;;; Commentary:
;; To know how to run the tests, see typescript-mode-tests.el
;;; Code:
(require 'ert)
(require 'typescript-mode)
(require 'cl-lib)
(require 'typescript-mode-test-utilities)
(defun typescript-test-get-doc ()
(buffer-substring-no-properties (point-min) (point-max)))
(defun typescript-test-indent-all ()
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max)))
(ert-deftest auto-mode-alist-ts ()
(find-file (make-temp-file load-file-name nil ".ts"))
(should (string-equal "typescript-mode" major-mode)))
(ert-deftest auto-mode-alist-tsx ()
(find-file (make-temp-file load-file-name nil ".tsx"))
(should (string-equal "typescript-mode" major-mode)))
(ert-deftest indentation-reference-document-is-reflowed-correctly ()
(with-temp-buffer
(insert-file-contents "test-files/indentation-reference-document.ts")
;; double ensure mode is active
(typescript-mode)
(let ((test-reference (typescript-test-get-doc)))
(typescript-test-indent-all)
(should (string-equal test-reference
(typescript-test-get-doc)))
(let ((typescript-indent-switch-clauses nil))
(typescript-test-indent-all)
(should (string-equal test-reference
(typescript-test-get-doc)))))))
(ert-deftest switch-case-indent-default ()
(with-temp-buffer
(insert-file-contents "test-files/switch-case-indent-default.ts")
(typescript-mode)
(let ((test-reference (typescript-test-get-doc)))
(typescript-test-indent-all)
(should (string-equal test-reference
(typescript-test-get-doc))))))
(ert-deftest switch-case-indent-disabled ()
(with-temp-buffer
(insert-file-contents "test-files/switch-case-indent-disabled.ts")
(let ((typescript-indent-switch-clauses nil))
(typescript-mode)
(let ((test-reference (typescript-test-get-doc)))
(typescript-test-indent-all)
(should (string-equal test-reference
(typescript-test-get-doc)))))))
(ert-deftest list-items-indent-default ()
(with-temp-buffer
(insert-file-contents "test-files/list-items-indent-default.ts")
(typescript-mode)
(let ((test-reference (typescript-test-get-doc)))
(typescript-test-indent-all)
(should (string= test-reference (typescript-test-get-doc))))))
(ert-deftest list-items-indent-default-not-comma-first ()
(with-temp-buffer
(insert-file-contents "test-files/list-items-indent-comma-first.ts")
(typescript-mode)
(let ((test-reference (typescript-test-get-doc)))
(typescript-test-indent-all)
(should-not (string= test-reference (typescript-test-get-doc))))))
(ert-deftest list-items-indent-comma-first ()
(with-temp-buffer
(insert-file-contents "test-files/list-items-indent-comma-first.ts")
(typescript-mode)
(let ((test-reference (typescript-test-get-doc))
(typescript-indent-list-items nil))
(typescript-test-indent-all)
(should (string= test-reference (typescript-test-get-doc))))))
(ert-deftest list-items-indent-comma-first-not-default ()
(with-temp-buffer
(insert-file-contents "test-files/list-items-indent-default.ts")
(typescript-mode)
(let ((test-reference (typescript-test-get-doc))
(typescript-indent-list-items nil))
(typescript-test-indent-all)
(should-not (string= test-reference (typescript-test-get-doc))))))
(defun get-all-matched-strings (to-match)
(let (result)
(dotimes (x (/ (length (match-data)) 2))
(setq result (nconc result (list (match-string x to-match)))))
result))
(ert-deftest typescript-tslint-report-regexp-matches ()
"typescript-tslint-report-regexp matches a line that does not
have a rule name or a severity."
(let* ((to-match
"src/modules/authenticator.ts[1, 83]: ' should be \"")
(match (string-match typescript-tslint-report-regexp
to-match))
(matches (and match (get-all-matched-strings to-match))))
(should match)
(should-not (nth 1 matches))
(should-not (nth 2 matches))
(should (string-equal (nth 3 matches)
"src/modules/authenticator.ts"))
(should (string-equal (nth 4 matches) "1"))
(should (string-equal (nth 5 matches) "83"))))
(ert-deftest typescript-tslint-report-regexp-matches-with-name ()
"typescript-tslint-report-regexp matches a line that has
a rule name, no severity."
(let* ((to-match
"(quotemark) src/modules/authenticator.ts[1, 83]: ' should be \"")
(match (string-match typescript-tslint-report-regexp
to-match))
(matches (and match (get-all-matched-strings to-match))))
(should match)
(should-not (nth 1 matches))
(should (string-equal (nth 2 matches) "(quotemark) "))
(should (string-equal (nth 3 matches)
"src/modules/authenticator.ts"))
(should (string-equal (nth 4 matches) "1"))
(should (string-equal (nth 5 matches) "83"))))
(ert-deftest typescript-tslint-report-regexp-matches-with-error ()
"typescript-tslint-report-regexp matches a line that has
a severity set to ERROR, no rule name."
(let* ((to-match
"ERROR: src/modules/authenticator.ts[1, 83]: ' should be \"")
(match (string-match typescript-tslint-report-regexp
to-match))
(matches (and match (get-all-matched-strings to-match))))
(should match)
(should-not (nth 1 matches))
(should-not (nth 2 matches))
(should (string-equal (nth 3 matches)
"src/modules/authenticator.ts"))
(should (string-equal (nth 4 matches) "1"))
(should (string-equal (nth 5 matches) "83"))))
(ert-deftest typescript-tslint-report-regexp-matches-with-warning ()
"typescript-tslint-report-regexp matches a line that has
a severity set to WARNING, no rule name."
(let* ((to-match
"WARNING: src/modules/authenticator.ts[1, 83]: ' should be \"")
(match (string-match typescript-tslint-report-regexp
to-match))
(matches (and match (get-all-matched-strings to-match))))
(should match)
(should (string-equal (nth 1 matches) "WARNING"))
(should-not (nth 2 matches))
(should (string-equal (nth 3 matches)
"src/modules/authenticator.ts"))
(should (string-equal (nth 4 matches) "1"))
(should (string-equal (nth 5 matches) "83"))))
(ert-deftest typescript--number-literal-re-matches-numbers ()
"`typescript--number-literal-re' matches numbers."
(dolist (to-match '("NaN" "Infinity" "-Infinity" "-1" "1" "0.1" ".1" "-.1" "8e23"
"9E-2" ".1e23" "0b1" "-0B1" "0o7" "-0O13" "0xaf" "-0XAF"))
(should (string-match typescript--number-literal-re to-match))
;; The regular expression does not begin with ^ and end with $ so
;; we need to check ourselves that the whole string is matched.
(should (string-equal (match-string 0 to-match) to-match))))
(ert-deftest typescript--number-literal-re-does-not-match-non-numbers ()
"`typescript--number-literal-re' does not match non-numbers."
(dolist (to-match '("NaNa" "Inf" "1." "." "0xPQ" "e" "2.3e2.4"))
;; For the same reason as for the positive test above, what we want is either no match
;; or a match that fails to match the whole string.
(should-not (and (string-match typescript--number-literal-re to-match)
(string-equal (match-string 0 to-match) to-match)))))
(ert-deftest correctly-indents-lines-with-wide-chars ()
"Otsuka Ai and other multi-char users should be a happy to write typescript."
(with-temp-buffer
(ignore-errors (typescript-mode))
(insert "let x = '大塚愛'")
(let ((pos1 (current-column)))
(typescript-indent-line)
(let ((pos2 (current-column)))
(should (= pos1 pos2))))))
(ert-deftest correctly-indents-lines-with-tabs ()
(with-temp-buffer
(ignore-errors (typescript-mode))
(insert "class Example {")
(newline-and-indent)
(insert "constructor() {")
(newline-and-indent)
(insert "const a = new Promise")
(should (= 29 (current-column)))
(typescript-indent-line)
(should (= 29 (current-column)))
;; verify tab was used
(move-beginning-of-line nil)
(should (= 0 (current-column)))
(forward-char 1)
(should (= 8 (current-column)))))
(ert-deftest correctly-indents-dot-dot-after-exclamation ()
(with-temp-buffer
(ignore-errors (typescript-mode))
(insert "situation('8/8/8/8/8/8/8/R3K2R w - - 0 1')?.")
(forward-char -1)
(newline-and-indent)
(should (= 4 (current-column)))))
(ert-deftest indentation-does-not-hang-on-multiline-string ()
"Testcase for https://github.com/ananthakumaran/typescript.el/issues/20"
(with-temp-buffer
(typescript-mode)
(insert "let multiLineString = \"line 1")
(newline-and-indent)
(insert "// and so we continue")
(newline-and-indent)
;; completing and not locking up is test-success!
))
(ert-deftest typescript--forward-expression-on-multiline-indented-string ()
"Testcase for https://github.com/emacs-typescript/typescript.el/issues/105"
(with-temp-buffer
(typescript-mode)
(insert
"fetch('http://localhost:8529/_db/_system/land', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
query: `{
query GetElement {
element(id: \"0000\") {
collection
id
name
description
}
}
}`,
}),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));")
(goto-char (point-min))
(typescript--forward-expression)
;; completing and not locking up is test-success!
;; Should there be a time-out? Or it is handled by external tool?
;; Check that `typescript--forward-expression' jumped to the right position.
(should (= 434 (point)))))
(defun test-re-search (searchee contents offset)
(with-temp-buffer
(typescript-mode)
(insert contents)
(goto-char (- (point-max) offset))
(should (= 5 (typescript--re-search-backward-inner searchee nil 1)))))
(ert-deftest re-search-backwards-skips-single-line-strings ()
(test-re-search "token" "let token = \"token in string-thing\";" 2))
(ert-deftest re-search-backwards-skips-multi-line-strings ()
(test-re-search "token" "let token = \"token in\n multi-line token string\";" 2))
(ert-deftest re-search-backwards-skips-single-line-comments ()
(test-re-search "token" "let token; // token in comment" 0))
(ert-deftest re-search-backwards-skips-multi-line-comments ()
(test-re-search "token" "let token; /* token in \nmulti-line token comment" 0))
(setq font-lock-contents
" * @param {Something} bar A parameter. References [[moo]] and [[foo]].
* @param second May hold ``x`` or ``y``.")
(ert-deftest font-lock/interface-builtin-key-context-unfontify ()
"Builtins should not be fontified when they are in object or
interface key context."
(test-with-fontified-buffer
"interface Foo { type: number; unknown: string; foo: boolean }"
(should (eq (get-face-at "type") 'default))
(should (eq (get-face-at "unknown") 'default)))
(test-with-fontified-buffer
"const x = { type: 4; unknown: 'bar'; foo: true }"
(should (eq (get-face-at "type") 'default))
(should (eq (get-face-at "unknown") 'default))))
(ert-deftest font-lock/documentation-in-documentation-comments ()
"Documentation in documentation comments should be fontified as
documentation."
(font-lock-test
(concat "/**\n" font-lock-contents "\n*/")
'((1 . font-lock-comment-delimiter-face)
(5 . font-lock-comment-face)
("@param" . typescript-jsdoc-tag)
("{Something}" . typescript-jsdoc-type)
("bar" . typescript-jsdoc-value)
("\\[\\[moo\\]\\]" . typescript-jsdoc-value)
("\\[\\[foo\\]\\]" . typescript-jsdoc-value)
("``x``" . typescript-jsdoc-value)
("``y``" . typescript-jsdoc-value))))
(ert-deftest font-lock/no-documentation-in-non-documentation-comments ()
"Documentation tags that are not in documentation comments
should not be fontified as documentation."
(test-with-fontified-buffer
(concat "/*\n" font-lock-contents "\n*/\n")
(let ((loc 3))
;; Make sure we start with the right face.
(should (eq (get-face-at loc) font-lock-comment-face))
(should (eq (text-property-not-all loc (point-max) 'face font-lock-comment-face)
(1- (point-max)))))))
(ert-deftest font-lock/no-documentation-in-strings ()
"Documentation tags that are not in strings should not be
fontified as documentation."
(test-with-fontified-buffer
(concat "const x = \"/**" font-lock-contents "*/\";")
(let ((loc (search-forward "\"")))
;; Make sure we start with the right face.
(should (eq (get-face-at loc) font-lock-string-face))
;; Make sure the face does not change later.
(should (eq (text-property-not-all loc (point-max) 'face font-lock-string-face)
(1- (point-max)))))))
(ert-deftest font-lock/immediate-doc ()
"Tests that it is not necessary to have the documentation tag on a
new line after the start of '/**'."
(font-lock-test
;; We have 4 comments here because we need to cover the multiple
;; regexes that deal with the different types of jsdoc tags.
"/** @type {foo} */\n
/** @alias bar */\n
/** @author me */\n
/** @param meow */"
'((1 . font-lock-comment-delimiter-face)
("@type" . typescript-jsdoc-tag)
("{foo}" . typescript-jsdoc-type)
("@alias" . typescript-jsdoc-tag)
("bar" . typescript-jsdoc-value)
("@author" . typescript-jsdoc-tag)
("me" . font-lock-comment-face)
("@param" . typescript-jsdoc-tag)
("meow" . typescript-jsdoc-value))))
(ert-deftest font-lock/function-definition-prefixes ()
"Tests that function names are highlighted in definitions, even
when prefixed with module modifiers."
(font-lock-test
"function basicDefn(x0: xty0, y0: yty0): ret0 {}\n
export function exportedDefn(x1: xty1, y1: yty1): ret1 {}\n
export default function exportedDefaultDefn(x2: xty2, y2: yty2): ret2 {}\n
declare function declareFunctionDefn(x3: xty3, y3: yty3): ret3;"
'(("basicDefn" . font-lock-function-name-face)
("exportedDefn" . font-lock-function-name-face)
("exportedDefaultDefn" . font-lock-function-name-face)
("declareFunctionDefn" . font-lock-function-name-face)
(("x0" "x1" "x2" "x3") . font-lock-variable-name-face)
(("\\by0" "\\by1" "\\by2" "\\by3") . font-lock-variable-name-face)
(("ret0" "ret1" "ret2" "ret3") . nil))))
(ert-deftest font-lock/level-four ()
"Tests the level four font lock highlights."
(font-lock-test
"@decorator\n
class Foo extends Bar {\n
private async innerExecuteAsync(endpoint: string, data?: any): Promise {\n
innerExecuteAsync(x: string, y: boolean, z: number, j?: any): Promise {\n
console.log(this.methodCall());\n
snake_cased_function(1, 2, 3)"
'(("@decorator" . font-lock-function-call-face)
("Foo" . font-lock-type-face)
("private" . typescript-access-modifier-face)
("innerExecuteAsync" . font-lock-function-name-face)
(("TResponse" "FResponse" "Response" "TValue") . font-lock-type-face)
("console" . font-lock-type-face)
("this" . typescript-this-face)
("methodCall" . font-lock-function-call-face)
("snake_cased_function" . font-lock-function-call-face)
(("string" "boolean" "number" "any") . typescript-primitive-face)
(("endpoint" "data") . font-lock-variable-name-face)
(("<" ">" ",") . nil))))
(ert-deftest font-lock/method-call-with-keyword-name ()
"If the name of the method is a keyword, it should still be highlighted as function."
(test-with-fontified-buffer
"const app = express();
app.get()
app.post()
app.delete()
if (true) {}
// for (abc) {}"
(should (eq (get-face-at "get") 'font-lock-function-call-face))
(should (eq (get-face-at "post") 'font-lock-function-call-face))
(should (eq (get-face-at "delete") 'font-lock-function-call-face))
(should (eq (get-face-at "if") 'font-lock-keyword-face))
(should (eq (get-face-at "for") 'font-lock-comment-face))))
(ert-deftest font-lock/generics ()
"Tests that type hints within generics are highlighted properly."
(font-lock-test
"const map = new Map()\n
function foo>>()\n"
'((("string" "number") . typescript-primitive-face)
("foo" . font-lock-function-name-face)
(("Z" "Y" "X") . font-lock-type-face)
(("<" ">" "," "&" "|") . nil))))
(ert-deftest font-lock/tsx ()
"Tests that tsx blocks are not considered generics by virtue of the <."
(font-lock-test
"test
"
'((("div" . nil)))))
(ert-deftest font-lock/regexp ()
"Regular expressions should be fontified as string constant."
(let ((content "=/foo/ (/bar/ ,/baz/ :/buzz/"))
(font-lock-test content
'(("=" . nil) ("/foo/" . font-lock-string-face)
("(" . nil) ("/bar/" . font-lock-string-face)
("," . nil) ("/baz/" . font-lock-string-face)
(":" . nil) ("/buzz/" . font-lock-string-face))))
;; Make sure that escaped forward slashes are handled too.
(font-lock-test "var a = /flip\\/flop/;"
'(("=" . nil)
(("/flip" "\\\\" "/" "flop/") . font-lock-string-face)
(";" . nil)))
;; Make sure a forward slash in a character class is handled fine.
;; It must not terminate the regular expression.
(font-lock-test "var a = /[/]/;"
'(("=" . nil)
(("/" "\\[/" "\\]/") . font-lock-string-face)
(";" . nil)))
;; Make sure an open bracket in a character class does not
;; throw off fontification.
(font-lock-test "var a = /[[]/;"
'(("=" . nil)
(("/" "\\[\\[\\]" "/") . font-lock-string-face)
(";" . nil)))
;; A sequence of two forward slashes is never a regex, so there is
;; no such thing as an \"empty regex\" when we use the forward slash
;; notation.
(font-lock-test "=//g something // comment"
'(("g something" . font-lock-comment-face))))
(ert-deftest font-lock/yield ()
"`yield' and `yield*' should be fontified as keywords."
(font-lock-test
"function* gen(x0: xty0, y0: yty0): ret0 {
yield 123;
yield* subIter;
}"
'(("yield 123" . font-lock-keyword-face)
("yield\\*" . font-lock-keyword-face)
("\\* subIter" . font-lock-keyword-face))))
(ert-deftest font-lock/yielder ()
"`yielder' should not be fontified as a keyword."
(font-lock-test
"function* gen(x0: xty0, y0: yty0): ret0 {
const yielder = 123;
yield abc;
return yielder;
}"
'(("yielder =" . font-lock-variable-name-face)
("yielder;" . nil))))
(ert-deftest font-lock/text-after-trailing-regexp-delim-should-not-be-fontified ()
"Text after trailing regular expression delimiter should not be fontified."
(test-with-fontified-buffer
"=/foo/g something // comment"
(should (eq (get-face-at "g something") nil)))
(test-with-fontified-buffer
"=/foo\\bar/g something // comment"
(should (eq (get-face-at "g something") nil)))
(test-with-fontified-buffer
"=/foo\\\\bar/g something // comment"
(should (eq (get-face-at "g something") nil)))
(test-with-fontified-buffer
"=/foo\\\\/g something // comment"
(should (eq (get-face-at "g something") nil))))
(ert-deftest font-lock/type-names ()
"Type names should be highlighted in definitions."
;; Typical case.
(test-with-fontified-buffer
"export class Foo extends Bar implements Qux {}"
(should (eq (get-face-at "Foo") 'font-lock-type-face))
(should (eq (get-face-at "Bar") 'font-lock-type-face))
(should (eq (get-face-at "Qux") 'font-lock-type-face)))
(test-with-fontified-buffer
"export class Foo extends Bar implements Qux, Ajx {}"
(should (eq (get-face-at "Foo") 'font-lock-type-face))
(should (eq (get-face-at "Bar") 'font-lock-type-face))
(should (eq (get-face-at "Qux") 'font-lock-type-face))
(should (eq (get-face-at ",") 'nil))
(should (eq (get-face-at "Ajx") 'font-lock-type-face)))
(test-with-fontified-buffer
"export class Foo extends Bar implements Qux, Ajx, Psd {}"
(should (eq (get-face-at "Foo") 'font-lock-type-face))
(should (eq (get-face-at "Bar") 'font-lock-type-face))
(should (eq (get-face-at "Qux") 'font-lock-type-face))
(should (eq (get-face-at ",") 'nil))
(should (eq (get-face-at "Ajx") 'font-lock-type-face))
(should (eq (get-face-at ",") 'nil))
(should (eq (get-face-at "Psd") 'font-lock-type-face)))
;; Ensure we require symbol boundaries.
(test-with-fontified-buffer
"Notclass Foo"
(should-not (eq (get-face-at "Foo") 'font-lock-type-face)))
;; Other common ways of defining types.
(test-with-fontified-buffer
"interface Thing {}"
(should (eq (get-face-at "Thing") 'font-lock-type-face)))
(test-with-fontified-buffer
"enum Thing {}"
(should (eq (get-face-at "Thing") 'font-lock-type-face)))
(test-with-fontified-buffer
"type Thing = number;"
(should (eq (get-face-at "Thing") 'font-lock-type-face))))
(ert-deftest font-lock/fontify-type-guard ()
"The type guard syntax
var is Type
should be fontified as variable, keyword and type."
(test-with-fontified-buffer
"function test(var: unknown): var is RetType {\n}"
(should (eq (get-face-at 30) 'font-lock-variable-name-face))
(should (eq (get-face-at "is") 'font-lock-keyword-face))
(should (eq (get-face-at "RetType") 'font-lock-type-face))))
(ert-deftest font-lock/type-names-level4 ()
"Typenames should be highlighted in declarations"
(test-with-fontified-buffer
"function test(var1: Type1, var2: Type2): RetType {\n}"
(should-not (eq (get-face-at "var1") 'font-lock-type-face))
(should (eq (get-face-at "Type1") 'font-lock-type-face))
(should-not (eq (get-face-at "var2") 'font-lock-type-face))
(should (eq (get-face-at "Type2") 'font-lock-type-face))
(should (eq (get-face-at "RetType") 'font-lock-type-face)))
(test-with-fontified-buffer
"class foo { test(var1: Type1, var2: Type2): RetType {\n} }"
(should-not (eq (get-face-at "var1") 'font-lock-type-face))
(should (eq (get-face-at "Type1") 'font-lock-type-face))
(should-not (eq (get-face-at "var2") 'font-lock-type-face))
(should (eq (get-face-at "Type2") 'font-lock-type-face))
(should (eq (get-face-at "RetType") 'font-lock-type-face)))
(test-with-fontified-buffer
"let a: SomeType;"
(should (eq (get-face-at "SomeType") 'font-lock-type-face)))
(test-with-fontified-buffer
"private b: SomeType;"
(should (eq (get-face-at "SomeType") 'font-lock-type-face)))
(test-with-fontified-buffer
"private someArray: SomeType[];"
(should (eq (get-face-at "SomeType") 'font-lock-type-face)))
(test-with-fontified-buffer
"private generic: SomeType;"
(should (eq (get-face-at "SomeType") 'font-lock-type-face))
(should (eq (get-face-at "Foo") 'font-lock-type-face)))
(test-with-fontified-buffer
"private genericArray: SomeType[];"
(should (eq (get-face-at "SomeType") 'font-lock-type-face))
(should (eq (get-face-at "Foo") 'font-lock-type-face)))
(test-with-fontified-buffer
"private genericArray2: SomeType;"
(should (eq (get-face-at "SomeType") 'font-lock-type-face))
(should (eq (get-face-at "Foo") 'font-lock-type-face)))
(test-with-fontified-buffer
"private genericArray3: SomeType[];"
(should (eq (get-face-at "SomeType") 'font-lock-type-face))
(should (eq (get-face-at "Foo") 'font-lock-type-face)))
(test-with-fontified-buffer
"const f: () => SomeType = () => {}"
(should (eq (get-face-at "SomeType") 'font-lock-type-face))))
(ert-deftest font-lock/type-names-level4-namespaces ()
"Namespaced Typenames should be highlighted in declarations"
(test-with-fontified-buffer
"private b: Namespaced.ClassName;"
(should (eq (get-face-at "Namespaced") 'font-lock-type-face))
(should (eq (get-face-at "ClassName") 'font-lock-type-face)))
(test-with-fontified-buffer
"function test(var1: Namespaced.ClassName): RetType {\n}"
(should (eq (get-face-at "Namespaced") 'font-lock-type-face))
(should (eq (get-face-at "ClassName") 'font-lock-type-face)))
(test-with-fontified-buffer
"class Foo { test(var1: Namespaced.ClassName): RetType {\n}"
(should (eq (get-face-at "Namespaced") 'font-lock-type-face))
(should (eq (get-face-at "ClassName") 'font-lock-type-face)))
(test-with-fontified-buffer
"function test(var1: Type): Namespaced.ClassName {\n}"
(should (eq (get-face-at "Namespaced") 'font-lock-type-face))
(should (eq (get-face-at "ClassName") 'font-lock-type-face)))
(test-with-fontified-buffer
"class Foo { test(var1: Type): Namespaced.ClassName {\n}"
(should (eq (get-face-at "Namespaced") 'font-lock-type-face))
(should (eq (get-face-at "ClassName") 'font-lock-type-face))))
(ert-deftest font-lock/funargs--function--multiline-with-types ()
"Variables should be highlighted in multiline declarations with types."
(test-with-fontified-buffer
"function test(
var1: Promise,
var2: (xxx: Foo) => Bar,
var3: Type3,
): RetType {\n}"
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))
(should (eq (get-face-at "var3") 'font-lock-variable-name-face))
(should (eq (get-face-at "xxx") 'font-lock-variable-name-face))
(should (eq (get-face-at "Promise") 'font-lock-type-face))
(should (eq (get-face-at "U1") 'font-lock-type-face))
(should (eq (get-face-at "Foo") 'font-lock-type-face))
(should (eq (get-face-at "Type3") 'font-lock-type-face))))
(ert-deftest font-lock/funargs--function--multiline-without-types ()
"Variables should be highlighted in multiline declarations without types."
(test-with-fontified-buffer
"function test(
var1,
var2,
): RetType {\n}"
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--function--multiline-hanging-paren ()
"Variables should be highlighted in multiline declarations with hanging paren."
(test-with-fontified-buffer
"function test(
var1,
var2): RetType {\n}"
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--function--multiline-ending-comma-hanging-paren ()
"Variables should be highlighted in multiline declarations with hanging paren and trailing comma."
(test-with-fontified-buffer
"function test(
var1,
var2,): RetType {\n}"
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--function--singleline-ending-comma-no-hanging-paren ()
"Variables should be highlighted in singleline declarations with no hanging paren and trailing comma."
(test-with-fontified-buffer
"function test(var1,var2,
): RetType {\n}"
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--function--singleline-with-types ()
"Variables should be highlighted in singleline declarations with types."
(test-with-fontified-buffer
"function test(var1: Foo, var2: Bar,): RetType {\n}"
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))
(should (eq (get-face-at "Foo") 'font-lock-type-face))
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
(ert-deftest font-lock/funargs--function--singleline-ending-comma-hanging-paren ()
"Variables should be highlighted in singleline declarations with hanging paren and trailing comma."
(test-with-fontified-buffer
"function test(var1,var2,): RetType {\n}"
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--function--keywords-as-variables ()
"Keywords when used as variables should have variable face"
(test-with-fontified-buffer
"function test(type, unknown): void {}"
(should (eq (get-face-at "type") 'font-lock-variable-name-face))
(should (eq (get-face-at "unknown") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--keywords-as-variables ()
"Keywords when used as variables should have variable face"
(test-with-fontified-buffer
"const test = (type, unknown): void => {}"
(should (eq (get-face-at "type") 'font-lock-variable-name-face))
(should (eq (get-face-at "unknown") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--single-line--no-type ()
(test-with-fontified-buffer
"const test = (aaa, bbb, ccc): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--single-line--no-type--no-return-type ()
(test-with-fontified-buffer
"const test = (aaa, bbb, ccc) => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--single-line--no-type--trailing-comma ()
(test-with-fontified-buffer
"const test = (aaa, bbb, ccc,): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--single-line--no-type--optional ()
(test-with-fontified-buffer
"const test = (aaa, bbb?): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb?") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--multiline--no-type ()
(test-with-fontified-buffer
"const test = (aaa, bbb,
ccc, ddd): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))
(should (eq (get-face-at "ddd") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--multiline--no-type--newline-after-last ()
(test-with-fontified-buffer
"const test = (aaa, bbb,
ccc, ddd
): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))
(should (eq (get-face-at "ddd") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--multiline--no-type--newline-before-first ()
(test-with-fontified-buffer
"const test = (
aaa, bbb,
ccc, ddd
): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))
(should (eq (get-face-at "ddd") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--multiline--no-type--with-comment ()
(test-with-fontified-buffer
"const test = (
aaa, bbb, // comment
ccc, ddd // comment
): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))
(should (eq (get-face-at "ddd") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--single--mixed-type--newline-before-first ()
(test-with-fontified-buffer
"const test = (aaa, bbb: Promise, ccc: number, ddd): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))
(should (eq (get-face-at "ddd") 'font-lock-variable-name-face))
(should (eq (get-face-at "Promise") 'font-lock-type-face))
(should (eq (get-face-at "number") 'typescript-primitive-face))))
(ert-deftest font-lock/funargs--arrow--single--with-type--complex-type ()
(test-with-fontified-buffer
"const test = (aaa: Promise Foo>, bbb): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "xxx") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--arrow--multiline--with-type--newline-before-first-after-last ()
(test-with-fontified-buffer
"const test = (
aaa: Foo,
bbb: Bar
): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "Foo") 'font-lock-type-face))
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
(ert-deftest font-lock/funargs--arrow--multiline--with-type--newline-before-first-after-last--hanging-comma ()
(test-with-fontified-buffer
"const test = (
aaa: Foo,
bbb: Bar,
): void => {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "Foo") 'font-lock-type-face))
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
(ert-deftest font-lock/backticks--expr-fontification--with-variable ()
(test-with-fontified-buffer
"const x = `hello ${world}`"
(should (eq (get-face-at "${") 'font-lock-keyword-face))
(should (eq (get-face-at "world") 'default))
(should (eq (get-face-at "}") 'font-lock-keyword-face))))
(ert-deftest font-lock/backticks--expr-fontification--not-in-regular-string ()
(test-with-fontified-buffer
"const x = 'hello ${world}'"
(should (eq (get-face-at "${") 'font-lock-string-face))
(should (eq (get-face-at "world") 'font-lock-string-face))
(should (eq (get-face-at "}") 'font-lock-string-face))))
(ert-deftest font-lock/backticks--expr-fontification--with-funcall ()
"For now function calls or any other expressions are fontified as
if a simple variable token in its entirety. When/if this is
implemented better, this test should be adjusted to capture the
new functionality."
(test-with-fontified-buffer
"const x = `hello ${parseInt(foobar)}`"
(should (eq (get-face-at "${") 'font-lock-keyword-face))
(should (eq (get-face-at "parseInt(foobar)") 'default))
(should (eq (get-face-at "}") 'font-lock-keyword-face))))
(ert-deftest font-lock/funargs--method--multiline--with-type ()
(test-with-fontified-buffer
"class Foo { foo(
aaa: Foo,
bbb: Bar,
): void {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "Foo") 'font-lock-type-face))
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
(ert-deftest font-lock/funargs--method--single-line--with-type ()
(test-with-fontified-buffer
"class Foo { foom(aaa: Foo,bbb: Bar,): void {}"
(should (eq (get-face-at "foom") 'font-lock-function-name-face))
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
(should (eq (get-face-at "Foo") 'font-lock-type-face))
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
(ert-deftest font-lock/funargs--method--single-line--no-type ()
(test-with-fontified-buffer
"class Foo { foo(aaa, bbb): void {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--method--single-line--no-return-type ()
(test-with-fontified-buffer
"class Foo { foo(aaa, bbb) {}"
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))))
(ert-deftest font-lock/funargs--method--no-fontification-in-ternary ()
"Do not apply fontification on a function call inside a ternary
operator, which might look like method with return type
declaration."
(test-with-fontified-buffer
"true ? funcall(helloWorld) : false"
(should (eq (get-face-at "helloWorld") nil))))
(ert-deftest font-lock/funargs--method--no-fontification-in-special-form ()
"Do not apply fontification inside a special form paren-form,
such as inside of if/while/switch etc. These look like method
declarations without a return type annotation but are not."
(test-with-fontified-buffer
"if (hello && world) { }"
(should (eq (get-face-at "world") nil))))
(defun flyspell-predicate-test (search-for)
"This function runs a test on
`typescript--flyspell-mode-predicate'. `SEARCH-FOR' is a string
to search for in the current buffer before running
`typescript--flyspell-mode-predicate'. This test checks that the
point has not moved. It returns the value of returned by the
invocation of `typescript--flyspell-mode-predicate'."
(search-forward search-for)
(let ((point-before (point)))
(prog1
(typescript--flyspell-mode-predicate)
;; We should not have moved.
(should (eq (point) point-before)))
))
(ert-deftest flyspell-mode-predicate-skips-what-it-should ()
"Check that the custom flyspell predicate filters strings in
import... from...."
(let (flyspell-generic-progmode-verify)
(fset 'flyspell-generic-progmode-verify (lambda () t))
;; In the following searches we search for the starting quote of the strings
;; to avoid hitting keywords. Moreover, the end position of the search is important.
;; Flyspell puts point at the end of the word before calling the predicate. We must
;; replicate that behavior here.
(test-with-fontified-buffer
"import 'a';\nimport { x } from 'b';\nconst foo = 'c';import { x }\nfrom 'd';"
(should-not (flyspell-predicate-test "'a"))
(should-not (flyspell-predicate-test "'b"))
(should (flyspell-predicate-test "'c"))
(should-not (flyspell-predicate-test "'d")))
(test-with-fontified-buffer
;; This is valid TypeScript.
"const from = 'a';"
(should (flyspell-predicate-test "'a")))
(test-with-fontified-buffer
;; TypeScript does not allow a function named "import" but object
;; members may be named "import". So this *can* be valid
;; TypeScript.
"x.import('a');"
(should (flyspell-predicate-test "'a")))))
(ert-deftest typescript--move-to-end-of-plain-string ()
"Unit tests for `typescript--move-to-end-of-plain-string'."
(cl-flet
((should-fail ()
(let ((point-before (point)))
(should-not (typescript--move-to-end-of-plain-string))
(should (eq (point) point-before))))
(should-not-fail (expected)
(let ((result (typescript--move-to-end-of-plain-string)))
(should (eq result expected))
(should (eq (point) expected)))))
;;
;; The tests below are structured as follows. For each case:
;;
;; 1. Move point to a new location in the buffer.
;;
;; 2. Check whether typescript--move-to-end-of-plain-string returns the value we expected
;; and changes (point) when successful.
;;
;; Cases often start with a check right away: (point) equal to
;; (point-min) for those cases.
;;
(dolist (delimiter '("'" "\""))
(test-with-temp-buffer
(replace-regexp-in-string "'" delimiter "const a = 'not terminated")
(should-fail)
(re-search-forward delimiter)
(should-fail))
(test-with-temp-buffer
(replace-regexp-in-string "'" delimiter "const a = 'terminated'")
(should-fail)
;; This checks that the function works when invoked on the start delimiter of
;; a terminated string.
(re-search-forward delimiter)
(should-not-fail (1- (point-max)))
(goto-char (point-min))
(re-search-forward "term")
(should-not-fail (1- (point-max)))
;; This checks that the function works when invoked on the end delimiter of
;; a terminated string.
(goto-char (1- (point-max)))
(should-not-fail (1- (point-max))))
(test-with-temp-buffer
(replace-regexp-in-string "'" delimiter "const a = 'terminated aaa';\n
const b = 'not terminated bbb")
(should-fail)
(re-search-forward "term")
(should-not-fail (save-excursion (re-search-forward "aaa")))
(re-search-forward "const b")
(should-fail)
(re-search-forward "not terminated")
(should-fail))
;; Case with escaped delimiter.
(test-with-temp-buffer
(replace-regexp-in-string "'" delimiter "const a = 'terminat\\'ed aaa';\n
const b = 'not terminated bbb")
(re-search-forward "term")
(should-not-fail (save-excursion (re-search-forward "aaa"))))
;; Delimiters in comments.
(test-with-temp-buffer
(replace-regexp-in-string "'" delimiter "const a = 'terminated aaa';\n
// Comment 'or'\n
const b = 'not terminated bbb")
(re-search-forward "term")
(should-not-fail (save-excursion (re-search-forward "aaa")))
(re-search-forward "Comment ")
(should-fail)
(forward-char)
(should-fail)
(re-search-forward "or")
(should-fail)))
;; Ignores template strings.
(test-with-temp-buffer
"const a = `terminated aaa`"
(re-search-forward "term")
(should-fail))))
(ert-deftest typescript-convert-to-template ()
"Unit tests for `typescript-convert-to-template'."
(cl-flet
((should-do-nothing (str regexp)
(test-with-temp-buffer
str
(re-search-forward regexp)
(typescript-convert-to-template)
(should (string-equal (typescript-test-get-doc) str))))
(should-modify (str delimiter regexp)
(test-with-temp-buffer
str
(re-search-forward regexp)
(typescript-convert-to-template)
(should (string-equal (typescript-test-get-doc)
(replace-regexp-in-string delimiter "`" str))))))
(dolist (delimiter '("'" "\""))
(let ((str (replace-regexp-in-string "'" delimiter "const a = 'not terminated")))
(dolist (move-to '("const" "not"))
(should-do-nothing str move-to)))
(let ((str (replace-regexp-in-string "'" delimiter "const a = 'terminated'")))
(should-do-nothing str "const")
(should-modify str delimiter delimiter)
(should-modify str delimiter "term")
(should-modify str delimiter "terminated"))
;; Delimiters in comments.
(let ((str (replace-regexp-in-string "'" delimiter "const a = 'terminated aaa';\n
// Comment 'or'\n
const b = 'not terminated bbb")))
(should-do-nothing str "Comment ")))
;; Ignores template strings.
(let ((str "const a = `terminated aaa`"))
(should-do-nothing str "terminated"))))
(ert-deftest typescript-autoconvert-to-template ()
"Unit tests for `typescript-autoconvert-to-template'."
(cl-flet
((should-do-nothing (str regexp)
(test-with-temp-buffer
str
(re-search-forward regexp)
(typescript-autoconvert-to-template)
(should (string-equal (typescript-test-get-doc) str))))
(should-modify (str delimiter regexp)
(test-with-temp-buffer
str
(re-search-forward regexp)
(typescript-autoconvert-to-template)
(should (string-equal (typescript-test-get-doc)
(replace-regexp-in-string delimiter "`" str))))))
(dolist (delimiter '("'" "\""))
(let ((str (replace-regexp-in-string "'" delimiter "const a = 'terminated'")))
(should-do-nothing str "= ")
(should-do-nothing str "terminated"))
(let ((str (replace-regexp-in-string "'" delimiter "const a = '${foo}'")))
(should-do-nothing str "= ")
(should-modify str delimiter (concat "foo}" delimiter))))))
(ert-deftest typescript-autoconvert-to-template-is-invoked ()
"Test that we call `typescript-autoconvert-to-template' as needed."
(cl-flet
((should-do-nothing (str delimiter)
(test-with-temp-buffer
str
(goto-char (point-max))
(execute-kbd-macro delimiter)
(should (string-equal (typescript-test-get-doc) (concat str delimiter)))))
(should-modify (str delimiter)
(test-with-temp-buffer
str
(goto-char (point-max))
(execute-kbd-macro delimiter)
(should (string-equal (typescript-test-get-doc)
(replace-regexp-in-string delimiter "`" (concat str delimiter)))))))
(dolist (delimiter '("'" "\""))
(let ((str (replace-regexp-in-string "'" delimiter "const a = '${foo}")))
(should-do-nothing str delimiter)
(let ((typescript-autoconvert-to-template-flag t))
(should-modify str delimiter))))))
;; compilation-mode tests
(ert-deftest recognizes-tsc-errors ()
(dolist (test-case
`(("test.ts(2,7): error TS2322: Type '2' is not assignable to type 'string'."
,typescript-tsc-error-regexp
"test.ts")
("test.ts:2:7 - error TS2322: Type '2' is not assignable to type 'string'."
,typescript-tsc-pretty-error-regexp
"test.ts")
))
(let* ((text (car test-case))
(regexp (cadr test-case))
(matched-file-name (cl-caddr test-case))
(times 1))
(with-temp-buffer
(insert text)
(goto-char (point-min))
(re-search-forward regexp)
(should
(equal matched-file-name (match-string 1)))))))
(provide 'typescript-mode-general-tests)
;;; typescript-mode-general-tests.el ends here
================================================
FILE: typescript-mode-jsdoc-tests.el
================================================
;;; typescript-mode-jsdoc-tests --- This file contains JSDoc related tests for typescript-mode.el
;;; Commentary:
;; To understand the definition of JSDoc tag,
;; see https://github.com/jsdoc3/jsdoc/blob/b21427343c7294bbf1f14c718a390f3e955e37cb/lib/jsdoc/tag.js#L153-L195
;; To know how to run the tests, see typescript-mode-tests.el
;;; Code:
(require 'ert)
(require 'typescript-mode)
(require 'typescript-mode-test-utilities)
(defun jsdoc-multiline-test (jsdoc-lines specs)
"Perform a multi-line JSDoc test against specs.
`JSDOC-LINES' are converted into a multi-line JS comment, and
the comment is tested against `SPECS'.
For more information about how to write `SPECS', see `font-lock-test'."
(let* ((unwrapped-comment-lines
(mapcar (lambda (line) (concat " * " line "\n")) jsdoc-lines))
(comment-lines
(append '("/**\n") unwrapped-comment-lines '(" */"))))
(font-lock-test
(apply #'concat comment-lines)
(cons
'(1 . font-lock-comment-delimiter-face)
specs))))
;; Internal tags (or essential tags)
;; See https://github.com/jsdoc3/jsdoc/blob/b21427343c7294bbf1f14c718a390f3e955e37cb/lib/jsdoc/tag/dictionary/definitions.js#L222-L256
(ert-deftest jsdoc/also-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @also tags and its alias."
(jsdoc-multiline-test
'(
"@also"
)
'(
;; ("@also$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/also-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @also tags and its alias."
(jsdoc-multiline-test
'(
"@also extra text"
)
'(
;; ("@also extra text" . typescript-jsdoc-tag)
("extra text" . font-lock-comment-face)
("text" . font-lock-comment-face)
)))
(ert-deftest jsdoc/also-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @also tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/description-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @description tags and its alias."
(jsdoc-multiline-test
'(
"@description descriptionInSingleWord"
"@description description about something"
"@description"
"multi-line description about other things"
"@desc descInSingleWord"
"@desc desc about something"
"@desc"
"multi-line desc about other things"
)
'(
("@description descriptionInSingleWord" . typescript-jsdoc-tag)
("descriptionInSingleWord" . font-lock-comment-face)
("@description description about something" . typescript-jsdoc-tag)
("description about something" . font-lock-comment-face)
("about something" . font-lock-comment-face)
("something" . font-lock-comment-face)
("@description$" . typescript-jsdoc-tag)
("multi-line description about other things" . font-lock-comment-face)
("@desc descInSingleWord" . typescript-jsdoc-tag)
("descInSingleWord" . font-lock-comment-face)
("@desc desc about something" . typescript-jsdoc-tag)
("desc about something" . font-lock-comment-face)
("about something" . font-lock-comment-face)
("something" . font-lock-comment-face)
("@desc$" . typescript-jsdoc-tag)
("multi-line desc about other things" . font-lock-comment-face)
)))
(ert-deftest jsdoc/description-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @description tags and its alias."
(jsdoc-multiline-test
'(
"@description {DescriptionType}"
"@desc {DescType}"
)
'(
("@description {DescriptionType}" . typescript-jsdoc-tag)
("{DescriptionType}" . font-lock-comment-face)
("@desc {DescType}" . typescript-jsdoc-tag)
("{DescType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/description-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @description tags and its alias."
(jsdoc-multiline-test
'(
"@description"
"@desc"
)
'(
;; ("@description$" . font-lock-comment-face)
;; ("@desc$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/kind-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @kind tags and its alias."
(jsdoc-multiline-test
'(
"@kind class"
"@kind constant"
"@kind event"
"@kind external"
"@kind file"
"@kind function"
"@kind member"
"@kind mixin"
"@kind module"
"@kind namespace"
"@kind typedef"
)
'(
("@kind class" . typescript-jsdoc-tag)
("class" . typescript-jsdoc-value)
("@kind constant" . typescript-jsdoc-tag)
("constant" . typescript-jsdoc-value)
("@kind event" . typescript-jsdoc-tag)
("event" . typescript-jsdoc-value)
("@kind external" . typescript-jsdoc-tag)
("external" . typescript-jsdoc-value)
("@kind file" . typescript-jsdoc-tag)
("file" . typescript-jsdoc-value)
("@kind function" . typescript-jsdoc-tag)
("function" . typescript-jsdoc-value)
("@kind member" . typescript-jsdoc-tag)
("member" . typescript-jsdoc-value)
("@kind mixin" . typescript-jsdoc-tag)
("mixin" . typescript-jsdoc-value)
("@kind module" . typescript-jsdoc-tag)
("module" . typescript-jsdoc-value)
("@kind namespace" . typescript-jsdoc-tag)
("namespace" . typescript-jsdoc-value)
("@kind typedef" . typescript-jsdoc-tag)
("typedef" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/kind-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @kind tags and its alias."
(jsdoc-multiline-test
'(
"@kind meaninglessKind"
"@kind {KindType}"
)
'(
("@kind meaninglessKind" . typescript-jsdoc-tag)
("meaninglessKind" . typescript-jsdoc-value)
("@kind {KindType}" . typescript-jsdoc-tag)
("{KindType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/kind-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @kind tags and its alias."
(jsdoc-multiline-test
'(
"@kind"
)
'(
("@kind$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/name-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @name tags and its alias."
(jsdoc-multiline-test
'(
"@name someName"
)
'(
("@name someName" . typescript-jsdoc-tag)
("someName" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/name-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @name tags and its alias."
(jsdoc-multiline-test
'(
"@name {NameType}"
)
'(
("@name {NameType}" . typescript-jsdoc-tag)
("{NameType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/name-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @name tags and its alias."
(jsdoc-multiline-test
'(
"@name"
)
'(
("@name$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/undocumented-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @undocumented tags and its alias."
(jsdoc-multiline-test
'(
"@undocumented"
)
'(
;; ("@undocumented" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/undocumented-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @undocumented tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/undocumented-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @undocumented tags and its alias."
(jsdoc-multiline-test
'(
"@undocumented invalidValue"
"@undocumented {InvalidType}"
)
'(
("@undocumented invalidValue" . font-lock-comment-face)
("invalidValue" . font-lock-comment-face)
("@undocumented {InvalidType}" . font-lock-comment-face)
("{InvalidType}" . font-lock-comment-face)
)))
;; Basic tags
;; See https://github.com/jsdoc3/jsdoc/blob/b21427343c7294bbf1f14c718a390f3e955e37cb/lib/jsdoc/tag/dictionary/definitions.js#L260-L858
;; for details of following tag tests
(ert-deftest jsdoc/abstract-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @abstract tags and its alias."
(jsdoc-multiline-test
'(
"@abstract"
"@virtual"
)
'(
("@abstract" . typescript-jsdoc-tag)
("@virtual" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/abstract-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @abstract tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/abstract-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @abstract tags and its alias."
(jsdoc-multiline-test
'(
"@abstract invalid extra value0"
"@abstract {InvalidType0}"
"@virtual invalid extra value1"
"@virtual {InvalidType1}"
)
'(
("@abstract invalid extra value0" . typescript-jsdoc-tag)
("invalid extra value0" . font-lock-comment-face)
("extra value0" . font-lock-comment-face)
("value0" . font-lock-comment-face)
("@abstract {InvalidType0}" . typescript-jsdoc-tag)
("{InvalidType0}" . font-lock-comment-face)
("@virtual invalid extra value1" . typescript-jsdoc-tag)
("invalid extra value1" . font-lock-comment-face)
("extra value1" . font-lock-comment-face)
("value1" . font-lock-comment-face)
("@virtual {InvalidType1}" . typescript-jsdoc-tag)
("{InvalidType1}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/access-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @access tags and its alias."
(jsdoc-multiline-test
'(
"@access package"
"@access private"
"@access protected"
"@access public"
)
'(
("@access package" . typescript-jsdoc-tag)
("package" . typescript-jsdoc-value)
("@access private" . typescript-jsdoc-tag)
("private" . typescript-jsdoc-value)
("@access protected" . typescript-jsdoc-tag)
("protected" . typescript-jsdoc-value)
("@access public" . typescript-jsdoc-tag)
("public" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/access-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @access tags and its alias."
(jsdoc-multiline-test
'(
"@access meaninglessAccess"
"@access {AccessType}"
)
'(
("@access meaninglessAccess" . typescript-jsdoc-tag)
("meaninglessAccess" . typescript-jsdoc-value)
("@access {AccessType}" . typescript-jsdoc-tag)
("{AccessType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/access-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @access tags and its alias."
(jsdoc-multiline-test
'(
"@access"
)
'(
("@access$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/alias-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @alias tags and its alias."
(jsdoc-multiline-test
'(
"@alias exampleAlias0"
"@alias somenamespace.exampleAlias1"
)
'(
("@alias exampleAlias0" . typescript-jsdoc-tag)
("exampleAlias0" . typescript-jsdoc-value)
("@alias somenamespace.exampleAlias1" . typescript-jsdoc-tag)
("somenamespace.exampleAlias1" . typescript-jsdoc-value)
("exampleAlias1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/alias-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @alias tags and its alias."
(jsdoc-multiline-test
'(
"@alias multiple words"
"@alias {AliasType}"
)
'(
("@alias multiple words" . typescript-jsdoc-tag)
("multiple words" . typescript-jsdoc-value)
;; ("words" . typescript-jsdoc-value)
("@alias {AliasType}" . typescript-jsdoc-tag)
("{AliasType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/alias-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @alias tags and its alias."
(jsdoc-multiline-test
'(
"@alias"
)
'(
("@alias$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/async-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @async tags and its alias."
(jsdoc-multiline-test
'(
"@async"
)
'(
("@async" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/async-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @async tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/async-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @async tags and its alias."
(jsdoc-multiline-test
'(
"@async invalid extra value"
"@async {InvalidType}"
)
'(
("@async invalid extra value" . typescript-jsdoc-tag)
("invalid extra value" . font-lock-comment-face)
("extra value" . font-lock-comment-face)
("value" . font-lock-comment-face)
("@async {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/augments-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @augments tags and its alias."
(jsdoc-multiline-test
'(
"@augments ExampleAugmented0"
"@augments {ExampleAugmented1}"
"@extends ExampleExtended0"
"@extends {ExampleExtended1}"
)
'(
("@augments ExampleAugmented0" . typescript-jsdoc-tag)
("ExampleAugmented0" . typescript-jsdoc-value)
("@augments {ExampleAugmented1}" . typescript-jsdoc-tag)
;; ("{ExampleAugmented1}" . typescript-jsdoc-type)
("@extends ExampleExtended0" . typescript-jsdoc-tag)
("ExampleExtended0" . typescript-jsdoc-value)
("@extends {ExampleExtended1}" . typescript-jsdoc-tag)
;; ("{ExampleExtended1}" . typescript-jsdoc-type)
)))
(ert-deftest jsdoc/augments-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @augments tags and its alias."
(jsdoc-multiline-test
'(
"@augments {ExampleAugmented0} extra augments value"
"@extends {ExampleExtended0} extra extends value"
)
'(
("@augments {ExampleAugmented0} extra augments value" . typescript-jsdoc-tag)
;; ("{ExampleAugmented0} extra augments value" . typescript-jsdoc-type)
("extra augments value" . font-lock-comment-face)
("augments value" . font-lock-comment-face)
("value" . font-lock-comment-face)
("@extends {ExampleExtended0} extra extends value" . typescript-jsdoc-tag)
;; ("{ExampleExtended0} extra extends value" . typescript-jsdoc-type)
("extra extends value" . font-lock-comment-face)
("extends value" . font-lock-comment-face)
("value" . font-lock-comment-face)
)))
(ert-deftest jsdoc/augments-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @augments tags and its alias."
(jsdoc-multiline-test
'(
"@augments"
"@extends"
)
'(
("@augments$" . font-lock-comment-face)
;; ("@extends$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/author-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @author tags and its alias."
(jsdoc-multiline-test
'(
"@author Exampleauthor"
"@author Exampleauthor Withfamilyname"
"@author Exampleauthor "
)
'(
("@author Exampleauthor$" . typescript-jsdoc-tag)
;; ("Exampleauthor" . typescript-jsdoc-value)
("@author Exampleauthor Withfamilyname" . typescript-jsdoc-tag)
;; ("Exampleauthor Withfamilyname" . typescript-jsdoc-value)
;; ("Withfamilyname" . typescript-jsdoc-value)
("@author Exampleauthor " . typescript-jsdoc-tag)
;; ("Exampleauthor " . typescript-jsdoc-value)
;; ("" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/author-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @author tags and its alias."
(jsdoc-multiline-test
'(
"@author {AuthorType}"
)
'(
("@author {AuthorType}" . typescript-jsdoc-tag)
;; ("{AuthorType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/author-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @author tags and its alias."
(jsdoc-multiline-test
'(
"@author"
)
'(
;; ("@author$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/borrows-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @borrows tags and its alias."
(jsdoc-multiline-test
'(
"@borrows something0"
"@borrows originalName as borrowedName"
)
'(
("@borrows something0" . typescript-jsdoc-tag)
("something0" . typescript-jsdoc-value)
("@borrows originalName as borrowedName" . typescript-jsdoc-tag)
("originalName as borrowedName" . typescript-jsdoc-value)
;; ("as borrowedName" . typescript-jsdoc-value)
;; ("borrowedName" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/borrows-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @borrows tags and its alias."
(jsdoc-multiline-test
'(
"@borrows meaningless multiple words"
"@borrows {BorrowType}"
)
'(
("@borrows meaningless multiple words" . typescript-jsdoc-tag)
("meaningless multiple words" . typescript-jsdoc-value)
;; ("multiple words" . typescript-jsdoc-value)
;; ("words" . typescript-jsdoc-value)
("@borrows {BorrowType}" . typescript-jsdoc-tag)
("{BorrowType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/borrows-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @borrows tags and its alias."
(jsdoc-multiline-test
'(
"@borrows"
"@borrows {InvalidType}"
)
'(
("@borrows$" . font-lock-comment-face)
;; ("@borrows {InvalidType}" . font-lock-comment-face)
;; ("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/class-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @class tags and its alias."
(jsdoc-multiline-test
'(
;; See https://github.com/jsdoc3/jsdoc/blob/b21427343c7294bbf1f14c718a390f3e955e37cb/lib/jsdoc/tag/dictionary/definitions.js#L318-L340
"@class"
"@class ExampleClass"
"@class Class tag for description0"
"@class"
"Class tag for description1"
"@constructor"
"@constructor ExampleClassConstructor"
;; You cannot use @constructor to describe class
)
'(
("@class$" . typescript-jsdoc-tag)
("@class ExampleClass" . typescript-jsdoc-tag)
;; ("ExampleClass" . typescript-jsdoc-value)
("@class Class tag for description0" . typescript-jsdoc-tag)
("Class tag for description0" . font-lock-comment-face)
("tag for description0" . font-lock-comment-face)
("for description0" . font-lock-comment-face)
("description0" . font-lock-comment-face)
("Class tag for description1" . font-lock-comment-face)
("tag for description1" . font-lock-comment-face)
("for description1" . font-lock-comment-face)
("description1" . font-lock-comment-face)
("@constructor" . typescript-jsdoc-tag)
;; ("ExampleClassConstructor" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/class-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @class tags and its alias."
(jsdoc-multiline-test
'(
"@class {ClassType}"
"@constructor {ConstructorType}"
)
'(
("@class {ClassType}" . typescript-jsdoc-tag)
;; ("{ClassType}" . typescript-jsdoc-value)
("@constructor {ConstructorType}" . typescript-jsdoc-tag)
;; ("{ConstructorType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/class-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @class tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/classdesc-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @classdesc tags and its alias."
(jsdoc-multiline-test
'(
"@classdesc"
"@classdesc This is class description0"
"@classdesc"
"This is class description1"
)
'(
("@classdesc$" . typescript-jsdoc-tag)
("@classdesc This is class description0" . typescript-jsdoc-tag)
("This is class description0" . font-lock-comment-face)
("is class description0" . font-lock-comment-face)
("class description0" . font-lock-comment-face)
("description0" . font-lock-comment-face)
("This is class description1" . font-lock-comment-face)
("is class description1" . font-lock-comment-face)
("class description1" . font-lock-comment-face)
("description1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/classdesc-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @classdesc tags and its alias."
(jsdoc-multiline-test
'(
"@classdesc {ClassDescType}"
)
'(
("@classdesc {ClassDescType}" . typescript-jsdoc-tag)
("{ClassDescType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/classdesc-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @classdesc tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/constant-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @constant tags and its alias."
(jsdoc-multiline-test
'(
"@constant"
"@constant {ConstantType0}"
"@constant constantName0"
"@constant {ConstantType1} constantName1"
"@const"
"@const {ConstType0}"
"@const constName0"
"@const {ConstType1} constName1"
)
'(
("@constant$" . typescript-jsdoc-tag)
("@constant {ConstantType0}" . typescript-jsdoc-tag)
;; ("{ConstantType0}" . typescript-jsdoc-type)
("@constant constantName0" . typescript-jsdoc-tag)
;; ("constantName0" . typescript-jsdoc-value)
("@constant {ConstantType1} constantName1" . typescript-jsdoc-tag)
;; ("{ConstantType1} constantName1" . typescript-jsdoc-type)
;; ("constantName1" . typescript-jsdoc-value)
("@const$" . typescript-jsdoc-tag)
("@const {ConstType0}" . typescript-jsdoc-tag)
;; ("{ConstType0}" . typescript-jsdoc-type)
("@const constName0" . typescript-jsdoc-tag)
;; ("constName0" . typescript-jsdoc-value)
("@const {ConstType1} constName1" . typescript-jsdoc-tag)
;; ("{ConstType1} constName1" . typescript-jsdoc-type)
;; ("constName1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/constant-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @constant tags and its alias."
(jsdoc-multiline-test
'(
"@constant extra value other than name for constant0"
"@const extra value other than name for const0"
)
'(
("@constant extra value other than name for constant0" . typescript-jsdoc-tag)
;; ("extra value other than name for constant0" . typescript-jsdoc-value)
("value other than name for constant0" . font-lock-comment-face)
("other than name for constant0" . font-lock-comment-face)
("than name for constant0" . font-lock-comment-face)
("name for constant0" . font-lock-comment-face)
("for constant0" . font-lock-comment-face)
("constant0" . font-lock-comment-face)
("@const extra value other than name for const0" . typescript-jsdoc-tag)
;; ("extra value other than name for const0" . typescript-jsdoc-value)
("value other than name for const0" . font-lock-comment-face)
("other than name for const0" . font-lock-comment-face)
("than name for const0" . font-lock-comment-face)
("name for const0" . font-lock-comment-face)
("for const0" . font-lock-comment-face)
("const0" . font-lock-comment-face)
)))
(ert-deftest jsdoc/constant-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @constant tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/constructs-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @constructs tags and its alias."
(jsdoc-multiline-test
'(
"@constructs"
"@constructs className"
"@constructs {@thisClass}"
)
'(
("@constructs$" . typescript-jsdoc-tag)
("@constructs className" . typescript-jsdoc-tag)
;; ("className" . typescript-jsdoc-value)
("@constructs {@thisClass}" . typescript-jsdoc-tag)
;; ("{@thisClass}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/constructs-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @constructs tags and its alias."
(jsdoc-multiline-test
'(
"@constructs className and extra description"
"@constructs {ClassType}"
)
'(
("@constructs className and extra description" . typescript-jsdoc-tag)
;; ("className and extra description" . typescript-jsdoc-value)
("and extra description" . font-lock-comment-face)
("extra description" . font-lock-comment-face)
("description" . font-lock-comment-face)
("@constructs {ClassType}" . typescript-jsdoc-tag)
;; ("{ClassType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/constructs-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @constructs tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/copyright-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @copyright tags and its alias."
(jsdoc-multiline-test
'(
"@copyright Some copyright texts"
)
'(
("@copyright Some copyright texts" . typescript-jsdoc-tag)
("Some copyright texts" . font-lock-comment-face)
("copyright texts" . font-lock-comment-face)
("texts" . font-lock-comment-face)
)))
(ert-deftest jsdoc/copyright-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @copyright tags and its alias."
(jsdoc-multiline-test
'(
"@copyright {InvalidType}"
)
'(
("@copyright {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/copyright-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @copyright tags and its alias."
(jsdoc-multiline-test
'(
"@copyright"
)
'(
;; ("@copyright$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/default-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @default tags and its alias."
(jsdoc-multiline-test
'(
"@default"
"@default 5"
"@default true"
"@defaultvalue"
"@defaultvalue null"
"@defaultvalue \"abc\""
)
'(
("@default$" . typescript-jsdoc-tag)
("@default 5" . typescript-jsdoc-tag)
;; ("5" . typescript-jsdoc-value)
("@default true" . typescript-jsdoc-tag)
;; ("true" . typescript-jsdoc-value)
("@defaultvalue$" . typescript-jsdoc-tag)
("@defaultvalue null" . typescript-jsdoc-tag)
;; ("null" . typescript-jsdoc-value)
("@defaultvalue \"abc\"" . typescript-jsdoc-tag)
;; ("\"abc\"" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/default-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @default tags and its alias."
(jsdoc-multiline-test
'(
"@default multiple values for default0"
"@default {DefaultType}"
"@defaultvalue multiple values for defaultvalue0"
"@defaultvalue {DefaultValueType}"
)
'(
("@default multiple values for default0" . typescript-jsdoc-tag)
;; ("multiple values for default0" . typescript-jsdoc-value)
;; ("values for default0" . typescript-jsdoc-value)
;; ("for default0" . typescript-jsdoc-value)
;; ("default0" . typescript-jsdoc-value)
("@default {DefaultType}" . typescript-jsdoc-tag)
;; ("{DefaultType}" . typescript-jsdoc-value)
("@defaultvalue multiple values for defaultvalue0" . typescript-jsdoc-tag)
;; ("multiple values for defaultvalue0" . typescript-jsdoc-value)
;; ("values for defaultvalue0" . typescript-jsdoc-value)
;; ("for defaultvalue0" . typescript-jsdoc-value)
;; ("defaultvalue0" . typescript-jsdoc-value)
("@defaultvalue {DefaultValueType}" . typescript-jsdoc-tag)
;; ("{DefaultValueType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/default-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @default tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/deprecated-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @deprecated tags and its alias."
(jsdoc-multiline-test
'(
"@deprecated"
"@deprecated Some explanations about deprecation"
)
'(
("@deprecated$" . typescript-jsdoc-tag)
("@deprecated Some explanations about deprecation" . typescript-jsdoc-tag)
("Some explanations about deprecation" . font-lock-comment-face)
("explanations about deprecation" . font-lock-comment-face)
("about deprecation" . font-lock-comment-face)
("deprecation" . font-lock-comment-face)
)))
(ert-deftest jsdoc/deprecated-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @deprecated tags and its alias."
(jsdoc-multiline-test
'(
"@deprecated {DeprecatedType}"
)
'(
("@deprecated {DeprecatedType}" . typescript-jsdoc-tag)
("{DeprecatedType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/deprecated-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @deprecated tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/enum-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @enum tags and its alias."
(jsdoc-multiline-test
'(
"@enum"
"@enum {EnumItemType}"
)
'(
("@enum$" . typescript-jsdoc-tag)
("@enum {EnumItemType}" . typescript-jsdoc-tag)
("{EnumItemType}" . typescript-jsdoc-type)
)))
(ert-deftest jsdoc/enum-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @enum tags and its alias."
(jsdoc-multiline-test
'(
"@enum meaningless description0"
"@enum {EnumItemType} meaningless description1"
)
'(
("@enum meaningless description0" . typescript-jsdoc-tag)
("meaningless description0" . font-lock-comment-face)
("description0" . font-lock-comment-face)
("@enum {EnumItemType} meaningless description1" . typescript-jsdoc-tag)
("{EnumItemType} meaningless description1" . typescript-jsdoc-type)
("meaningless description1" . font-lock-comment-face)
("description1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/enum-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @enum tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/event-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @event tags and its alias."
(jsdoc-multiline-test
'(
"@event"
"@event SomeClass#exampleEvent"
)
'(
("@event$" . typescript-jsdoc-tag)
("@event SomeClass#exampleEvent" . typescript-jsdoc-tag)
;; ("SomeClass#exampleEvent" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/event-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @event tags and its alias."
(jsdoc-multiline-test
'(
"@event justText"
"@event {EventType}"
)
'(
("@event justText" . typescript-jsdoc-tag)
;; ("justText" . typescript-jsdoc-value)
("@event {EventType}" . typescript-jsdoc-tag)
;; ("{EventType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/event-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @event tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/example-tag-in-multiline-doc-comment-with-meaninglful-cases ()
"Test for meaningful and valid usage of @example tags and its alias."
(jsdoc-multiline-test
'(
"@example inlineExample with multiple terms0"
"@example"
"With multiline and multiple terms1"
)
'(
("@example inlineExample with multiple terms" . typescript-jsdoc-tag)
;; ("inlineExample with multiple terms" . typescript-jsdoc-value)
;; ("with multiple terms" . typescript-jsdoc-value)
;; ("multiple terms" . typescript-jsdoc-value)
;; ("terms" . typescript-jsdoc-value)
("@example$" . typescript-jsdoc-tag)
;; ("With multiline and multiple terms1" . typescript-jsdoc-value)
;; ("multiline and multiple terms1" . typescript-jsdoc-value)
;; ("and multiple terms1" . typescript-jsdoc-value)
;; ("multiple terms1" . typescript-jsdoc-value)
;; ("terms1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/example-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @example tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/example-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @example tags and its alias."
(jsdoc-multiline-test
'(
"@example"
)
'(
;; ("@example$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/exports-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @exports tags and its alias."
(jsdoc-multiline-test
'(
"@exports some/module"
)
'(
("@exports some/module" . typescript-jsdoc-tag)
;; ("some/module" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/exports-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @exports tags and its alias."
(jsdoc-multiline-test
'(
"@exports justText"
"@exports {ExportType}"
)
'(
("@exports justText" . typescript-jsdoc-tag)
;; ("justText" . typescript-jsdoc-value)
("@exports {ExportType}" . typescript-jsdoc-tag)
;; ("{ExportType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/exports-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @exports tags and its alias."
(jsdoc-multiline-test
'(
"@exports"
)
'(
;; ("@exports$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/external-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @external tags and its alias."
(jsdoc-multiline-test
'(
"@external"
"@external String"
"@external \"jQuery.fn\""
"@external {ExternalType0}"
"@external {ExternalType1} ExternalValue"
"@host"
"@host Boolean"
"@host \"jQuery.fn.pluginNamespace\""
"@host {HostType0}"
"@host {HostType1} HostValue"
)
'(
;; ("@external$" . typescript-jsdoc-tag)
("@external String" . typescript-jsdoc-tag)
("String" . typescript-jsdoc-value)
("@external \"jQuery.fn\"" . typescript-jsdoc-tag)
("\"jQuery.fn\"" . typescript-jsdoc-value)
("@external {ExternalType0}" . typescript-jsdoc-tag)
;; ("{ExternalType0}" . typescript-jsdoc-type)
("@external {ExternalType1} ExternalValue" . typescript-jsdoc-tag)
;; ("{ExternalType1} ExternalValue" . typescript-jsdoc-type)
;; ("ExternalValue" . typescript-jsdoc-value)
;; ("@host$" . typescript-jsdoc-tag)
("@host Boolean" . typescript-jsdoc-tag)
("Boolean" . typescript-jsdoc-value)
("@host \"jQuery.fn.pluginNamespace\"" . typescript-jsdoc-tag)
("\"jQuery.fn.pluginNamespace\"" . typescript-jsdoc-value)
("@host {HostType0}" . typescript-jsdoc-tag)
;; ("{HostType0}" . typescript-jsdoc-type)
("@host {HostType1} HostValue" . typescript-jsdoc-tag)
;; ("{HostType1} HostValue" . typescript-jsdoc-type)
;; ("HostValue" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/external-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @external tags and its alias."
(jsdoc-multiline-test
'(
"@external multiple words0"
"@host multiple words1"
)
'(
("@external multiple words0" . typescript-jsdoc-tag)
("multiple words0" . typescript-jsdoc-value)
;; ("words0" . typescript-jsdoc-value)
("@host multiple words1" . typescript-jsdoc-tag)
("multiple words1" . typescript-jsdoc-value)
;; ("words1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/external-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @external tags and its alias."
(jsdoc-multiline-test
'(
"@external"
)
'(
;; ("@external$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/file-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @file tags and its alias."
(jsdoc-multiline-test
'(
"@file"
"@file description for file0"
"@fileoverview"
"@fileoverview description for file1"
"@overview"
"@overview description for file2"
)
'(
("@file$" . typescript-jsdoc-tag)
("@file description for file0" . typescript-jsdoc-tag)
("description for file0" . font-lock-comment-face)
("for file0" . font-lock-comment-face)
("file0" . font-lock-comment-face)
("@fileoverview$" . typescript-jsdoc-tag)
("@fileoverview description for file1" . typescript-jsdoc-tag)
("description for file1" . font-lock-comment-face)
("for file1" . font-lock-comment-face)
("file1" . font-lock-comment-face)
("@overview$" . typescript-jsdoc-tag)
("@overview description for file2" . typescript-jsdoc-tag)
("description for file2" . font-lock-comment-face)
("for file2" . font-lock-comment-face)
("file2" . font-lock-comment-face)
)))
(ert-deftest jsdoc/file-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @file tags and its alias."
(jsdoc-multiline-test
'(
"@file {FileType}"
"@fileoverview {FileOverviewType}"
"@overview {OverviewType}"
)
'(
("@file {FileType}" . typescript-jsdoc-tag)
("{FileType}" . font-lock-comment-face)
("@fileoverview {FileOverviewType}" . typescript-jsdoc-tag)
("{FileOverviewType}" . font-lock-comment-face)
("@overview {OverviewType}" . typescript-jsdoc-tag)
("{OverviewType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/file-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @file tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/fires-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @fires tags and its alias."
(jsdoc-multiline-test
'(
"@fires SomeClass#eventName0"
"@emits SomeClass#eventName1"
)
'(
("@fires SomeClass#eventName0" . typescript-jsdoc-tag)
("SomeClass#eventName0" . typescript-jsdoc-value)
("@emits SomeClass#eventName1" . typescript-jsdoc-tag)
("SomeClass#eventName1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/fires-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @fires tags and its alias."
(jsdoc-multiline-test
'(
"@fires just text"
"@fires {FiresType}"
"@emits any text"
"@emits {EmitsType}"
)
'(
("@fires just text" . typescript-jsdoc-tag)
("just text" . typescript-jsdoc-value)
("text" . font-lock-comment-face)
("@fires {FiresType}" . typescript-jsdoc-tag)
("{FiresType}" . typescript-jsdoc-value)
("@emits any text" . typescript-jsdoc-tag)
("any text" . typescript-jsdoc-value)
("text" . font-lock-comment-face)
("@emits {EmitsType}" . typescript-jsdoc-tag)
("{EmitsType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/fires-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @fires tags and its alias."
(jsdoc-multiline-test
'(
"@fires"
"@emits"
)
'(
("@fires$" . font-lock-comment-face)
("@emits$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/function-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @function tags and its alias."
(jsdoc-multiline-test
'(
"@function"
"@function functionName"
"@func"
"@func funcName"
"@method"
"@method methodName"
)
'(
("@function$" . typescript-jsdoc-tag)
("@function functionName" . typescript-jsdoc-tag)
("functionName" . typescript-jsdoc-value)
("@func$" . typescript-jsdoc-tag)
("@func funcName" . typescript-jsdoc-tag)
("funcName" . typescript-jsdoc-value)
("@method$" . typescript-jsdoc-tag)
("@method methodName" . typescript-jsdoc-tag)
("methodName" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/function-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @function tags and its alias."
(jsdoc-multiline-test
'(
"@function multiple words for function0"
"@function {FunctionType}"
"@func multiple words for func0"
"@func {FuncType}"
"@method multiple words for method0"
"@method {MethodType}"
)
'(
("@function multiple words for function0" . typescript-jsdoc-tag)
("multiple words for function0" . typescript-jsdoc-value)
("words for function0" . font-lock-comment-face)
("for function0" . font-lock-comment-face)
("function0" . font-lock-comment-face)
("@function {FunctionType}" . typescript-jsdoc-tag)
("{FunctionType}" . typescript-jsdoc-value)
("@func multiple words for func0" . typescript-jsdoc-tag)
("multiple words for func0" . typescript-jsdoc-value)
("words for func0" . font-lock-comment-face)
("for func0" . font-lock-comment-face)
("func0" . font-lock-comment-face)
("@func {FuncType}" . typescript-jsdoc-tag)
("{FuncType}" . typescript-jsdoc-value)
("@method multiple words for method0" . typescript-jsdoc-tag)
("multiple words for method0" . typescript-jsdoc-value)
("words for method0" . font-lock-comment-face)
("for method0" . font-lock-comment-face)
("method0" . font-lock-comment-face)
("@method {MethodType}" . typescript-jsdoc-tag)
("{MethodType}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/function-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @function tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/generator-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @generator tags and its alias."
(jsdoc-multiline-test
'(
"@generator"
)
'(
("@generator$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/generator-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @generator tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/generator-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @generator tags and its alias."
(jsdoc-multiline-test
'(
"@generator invalid extra values"
"@generator {InvalidType}"
)
'(
("@generator invalid extra values" . typescript-jsdoc-tag)
("invalid extra values" . font-lock-comment-face)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@generator {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/global-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @global tags and its alias."
(jsdoc-multiline-test
'(
"@global"
)
'(
("@global$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/global-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @global tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/global-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @global tags and its alias."
(jsdoc-multiline-test
'(
"@global invalid extra values"
"@global {InvalidType}"
)
'(
("@global invalid extra values" . typescript-jsdoc-tag)
("invalid extra values" . font-lock-comment-face)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@global {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/hideconstructor-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @hideconstructor tags and its alias."
(jsdoc-multiline-test
'(
"@hideconstructor"
)
'(
("@hideconstructor$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/hideconstructor-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @hideconstructor tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/hideconstructor-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @hideconstructor tags and its alias."
(jsdoc-multiline-test
'(
"@hideconstructor invalid extra values"
"@hideconstructor {InvalidType}"
)
'(
("@hideconstructor invalid extra values" . typescript-jsdoc-tag)
("invalid extra values" . font-lock-comment-face)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@hideconstructor {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/ignore-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @ignore tags and its alias."
(jsdoc-multiline-test
'(
"@ignore"
)
'(
("@ignore$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/ignore-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @ignore tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/ignore-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @ignore tags and its alias."
(jsdoc-multiline-test
'(
"@ignore invalid extra values"
"@ignore {InvalidType}"
)
'(
("@ignore invalid extra values" . typescript-jsdoc-tag)
("invalid extra values" . font-lock-comment-face)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@ignore {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/implements-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @implements tags and its alias."
(jsdoc-multiline-test
'(
"@implements SomeInterface"
"@implements {OtherInterface}"
)
'(
("@implements SomeInterface" . typescript-jsdoc-tag)
;; ("SomeInterface" . typescript-jsdoc-value)
("@implements {OtherInterface}" . typescript-jsdoc-tag)
("{OtherInterface}" . typescript-jsdoc-type)
)))
(ert-deftest jsdoc/implements-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @implements tags and its alias."
(jsdoc-multiline-test
'(
"@implements {Interface0} Interface1"
)
'(
("@implements {Interface0} Interface1" . typescript-jsdoc-tag)
("{Interface0} Interface1" . typescript-jsdoc-type)
("Interface1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/implements-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @implements tags and its alias."
(jsdoc-multiline-test
'(
"@implements"
)
'(
;; ("@implements$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/inheritdoc-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @inheritdoc tags and its alias."
(jsdoc-multiline-test
'(
"@inheritdoc"
)
'(
("@inheritdoc$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/inheritdoc-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @inheritdoc tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/inheritdoc-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @inheritdoc tags and its alias."
(jsdoc-multiline-test
'(
"@inheritdoc invalid extra values"
"@inheritdoc {InvalidType}"
)
'(
("@inheritdoc invalid extra values" . typescript-jsdoc-tag)
("invalid extra values" . font-lock-comment-face)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@inheritdoc {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/inner-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @inner tags and its alias."
(jsdoc-multiline-test
'(
"@inner"
)
'(
("@inner$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/inner-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @inner tags and its alias."
(jsdoc-multiline-test
'(
"@inner extra values"
"@inner {InnerType}"
)
'(
("@inner extra values" . typescript-jsdoc-tag)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@inner {InnerType}" . typescript-jsdoc-tag)
("{InnerType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/inner-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @inner tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/instance-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @instance tags and its alias."
(jsdoc-multiline-test
'(
"@instance"
)
'(
("@instance$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/instance-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @instance tags and its alias."
(jsdoc-multiline-test
'(
"@instance extra values"
"@instance {InstanceType}"
)
'(
("@instance extra values" . typescript-jsdoc-tag)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@instance {InstanceType}" . typescript-jsdoc-tag)
("{InstanceType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/instance-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @instance tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/interface-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @interface tags and its alias."
(jsdoc-multiline-test
'(
"@interface"
"@interface InterfaceName"
)
'(
("@interface$" . typescript-jsdoc-tag)
("@interface InterfaceName" . typescript-jsdoc-tag)
;; ("InterfaceName" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/interface-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @interface tags and its alias."
(jsdoc-multiline-test
'(
"@interface extra values"
"@interface {InterfaceType0}"
"@interface {InterfaceType1} AndName"
)
'(
("@interface extra values" . typescript-jsdoc-tag)
;; ("extra values" . typescript-jsdoc-value)
("values" . font-lock-comment-face)
("@interface {InterfaceType0}" . typescript-jsdoc-tag)
;; ("{InterfaceType0}" . typescript-jsdoc-value)
("@interface {InterfaceType1} AndName" . typescript-jsdoc-tag)
;; ("{InterfaceType1} AndName" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/interface-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @interface tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/lends-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @lends tags and its alias."
(jsdoc-multiline-test
'(
"@lends"
"@lends Something"
"@lends Something.deeper"
)
'(
("@lends$" . typescript-jsdoc-tag)
("@lends Something" . typescript-jsdoc-tag)
;; ("Something" . typescript-jsdoc-value)
("@lends Something.deeper" . typescript-jsdoc-tag)
;; ("Something.deeper" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/lends-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @lends tags and its alias."
(jsdoc-multiline-test
'(
"@lends {LendsType0}"
"@lends {LendsType1} With.some.path"
)
'(
("@lends {LendsType0}" . typescript-jsdoc-tag)
;; ("{LendsType0}" . nil)
("@lends {LendsType1} With.some.path" . typescript-jsdoc-tag)
;; ("{LendsType1} With.some.path" . nil)
;; ("With.some.path" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/lends-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @lends tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/license-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @license tags and its alias."
(jsdoc-multiline-test
'(
"@license Some-License-Name"
"@license"
"Some long license texts"
)
'(
("@license Some-License-Name" . typescript-jsdoc-tag)
("Some-License-Name" . font-lock-comment-face)
("@license$" . typescript-jsdoc-tag)
("Some long license texts" . font-lock-comment-face)
("long license texts" . font-lock-comment-face)
("license texts" . font-lock-comment-face)
("texts" . font-lock-comment-face)
)))
(ert-deftest jsdoc/license-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @license tags and its alias."
(jsdoc-multiline-test
'(
"@license {LicenseType0}"
"@license {LicenseType1} With more text"
)
'(
("@license {LicenseType0}" . typescript-jsdoc-tag)
("{LicenseType0}" . font-lock-comment-face)
("@license {LicenseType1} With more text" . typescript-jsdoc-tag)
("{LicenseType1} With more text" . font-lock-comment-face)
("With more text" . font-lock-comment-face)
("more text" . font-lock-comment-face)
("text" . font-lock-comment-face)
)))
(ert-deftest jsdoc/license-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @license tags and its alias."
(jsdoc-multiline-test
'(
"@license"
)
'(
;; ("@license$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/listens-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @listens tags and its alias."
(jsdoc-multiline-test
'(
"@listens event:nameOfEvent"
)
'(
("@listens event:nameOfEvent" . typescript-jsdoc-tag)
("event:nameOfEvent" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/listens-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @listens tags and its alias."
(jsdoc-multiline-test
'(
"@listens extra text0"
"@listens {ListenType0}"
"@listens {ListenType1} and text1"
)
'(
("@listens extra text0" . typescript-jsdoc-tag)
("extra text0" . typescript-jsdoc-value)
;; ("text0" . typescript-jsdoc-value)
("@listens {ListenType0}" . typescript-jsdoc-tag)
("{ListenType0}" . typescript-jsdoc-value)
("@listens {ListenType1} and text1" . typescript-jsdoc-tag)
("{ListenType1} and text1" . typescript-jsdoc-value)
;; ("and text1" . typescript-jsdoc-value)
;; ("text1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/listens-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @listens tags and its alias."
(jsdoc-multiline-test
'(
"@listens"
)
'(
("@listens$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/member-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @member tags and its alias."
(jsdoc-multiline-test
'(
"@member"
"@member {MemberType0}"
"@member memberName0"
"@member {MemberType1} memberName1"
"@var"
"@var {VarType0}"
"@var varName0"
"@var {VarType1} varName1"
)
'(
;; ("@member$" . typescript-jsdoc-tag)
("@member {MemberType0}" . typescript-jsdoc-tag)
;; ("{MemberType0}" . typescript-jsdoc-type)
("@member memberName0" . typescript-jsdoc-tag)
("memberName0" . typescript-jsdoc-value)
("@member {MemberType1} memberName1" . typescript-jsdoc-tag)
;; ("{MemberType1} memberName1" . typescript-jsdoc-type)
;; ("memberName1" . typescript-jsdoc-value)
;; ("@var$" . typescript-jsdoc-tag)
("@var {VarType0}" . typescript-jsdoc-tag)
;; ;; ("{VarType0}" . typescript-jsdoc-type)
("@var varName0" . typescript-jsdoc-tag)
("varName0" . typescript-jsdoc-value)
("@var {VarType1} varName1" . typescript-jsdoc-tag)
;; ("{VarType1} varName1" . typescript-jsdoc-type)
;; ("varName1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/member-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @member tags and its alias."
(jsdoc-multiline-test
'(
"@member extra value0"
"@var extra value1"
)
'(
("@member extra value0" . typescript-jsdoc-tag)
("extra value0" . typescript-jsdoc-value)
("value0" . font-lock-comment-face)
("@var extra value1" . typescript-jsdoc-tag)
("extra value1" . typescript-jsdoc-value)
("value1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/member-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @member tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/memberof-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @memberof tags and its alias."
(jsdoc-multiline-test
'(
"@memberof SomeClass0"
"@memberof SomeClass1#"
"@memberof "
"@memberof! OtherClass0"
"@memberof! OtherClass1#"
;; "@memberof! " is valid, but it is hard to test.
)
'(
("@memberof SomeClass0" . typescript-jsdoc-tag)
("SomeClass0" . typescript-jsdoc-value)
("@memberof SomeClass1#" . typescript-jsdoc-tag)
("SomeClass1#" . typescript-jsdoc-value)
("@memberof " . typescript-jsdoc-tag)
("" . typescript-jsdoc-value)
;; ("@memberof! OtherClass0" . typescript-jsdoc-tag)
;; ("OtherClass0" . typescript-jsdoc-value)
;; ("@memberof! OtherClass1#" . typescript-jsdoc-tag)
;; ("OtherClass1#" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/memberof-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @memberof tags and its alias."
(jsdoc-multiline-test
'(
"@memberof extra text0"
"@memberof {MemberOfType0}"
"@memberof {MemberOfType1} and text1"
"@memberof! again string0"
"@memberof! {MemberOfForcedType0}"
"@memberof! {MemberOfForcedType1} and more string1"
)
'(
("@memberof extra text0" . typescript-jsdoc-tag)
("extra text0" . typescript-jsdoc-value)
;; ("text0" . typescript-jsdoc-value)
("@memberof {MemberOfType0}" . typescript-jsdoc-tag)
("{MemberOfType0}" . typescript-jsdoc-value)
("@memberof {MemberOfType1} and text1" . typescript-jsdoc-tag)
("{MemberOfType1} and text1" . typescript-jsdoc-value)
;; ("and text1" . typescript-jsdoc-value)
;; ("text1" . typescript-jsdoc-value)
;; ("@memberof! again string0" . typescript-jsdoc-tag)
;; ("again string0" . typescript-jsdoc-value)
;; ("string0" . typescript-jsdoc-value)
;; ("@memberof! {MemberOfForcedType0}" . typescript-jsdoc-tag)
;; ("{MemberOfForcedType0}" . typescript-jsdoc-value)
;; ("@memberof! {MemberOfForcedType1} and more string1" . typescript-jsdoc-tag)
;; ("{MemberOfForcedType1} and more string1" . typescript-jsdoc-value)
;; ("and more string1" . typescript-jsdoc-value)
;; ("more string1" . typescript-jsdoc-value)
;; ("string1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/memberof-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @memberof tags and its alias."
(jsdoc-multiline-test
'(
"@memberof"
"@memberof!"
)
'(
("@memberof$" . font-lock-comment-face)
("@memberof!$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/mixes-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @mixes tags and its alias."
(jsdoc-multiline-test
'(
"@mixes OtherObject"
)
'(
("@mixes OtherObject" . typescript-jsdoc-tag)
("OtherObject" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/mixes-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @mixes tags and its alias."
(jsdoc-multiline-test
'(
"@mixes extra text0"
"@mixes {MixesType0}"
"@mixes {MixesType1} and text1"
)
'(
("@mixes extra text0" . typescript-jsdoc-tag)
("extra text0" . typescript-jsdoc-value)
("text0" . font-lock-comment-face)
("@mixes {MixesType0}" . typescript-jsdoc-tag)
("{MixesType0}" . typescript-jsdoc-value)
("@mixes {MixesType1} and text1" . typescript-jsdoc-tag)
("{MixesType1} and text1" . typescript-jsdoc-value)
("and text1" . font-lock-comment-face)
("text1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/mixes-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @mixes tags and its alias."
(jsdoc-multiline-test
'(
"@mixes"
)
'(
("@mixes$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/mixin-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @mixin tags and its alias."
(jsdoc-multiline-test
'(
"@mixin"
"@mixin MixinName"
)
'(
("@mixin$" . typescript-jsdoc-tag)
("@mixin MixinName" . typescript-jsdoc-tag)
;; ("MixinName" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/mixin-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @mixin tags and its alias."
(jsdoc-multiline-test
'(
"@mixin and extra text0"
"@mixin {MixinType0}"
"@mixin {MixinType1} with more text1"
)
'(
("@mixin and extra text0" . typescript-jsdoc-tag)
;; ("and extra text0" . typescript-jsdoc-value)
("extra text0" . font-lock-comment-face)
("text0" . font-lock-comment-face)
("@mixin {MixinType0}" . typescript-jsdoc-tag)
;; ("{MixinType0}" . typescript-jsdoc-value)
("@mixin {MixinType1} with more text1" . typescript-jsdoc-tag)
;; ("{MixinType1} with more text1" . typescript-jsdoc-value)
("with more text1" . font-lock-comment-face)
("more text1" . font-lock-comment-face)
("text1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/mixin-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @mixin tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
;; @modified tag is not yet released (It is a new tag of JSDoc 3.6.0)
(ert-deftest jsdoc/modifies-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @modifies tags and its alias."
(jsdoc-multiline-test
'(
"@modifies"
"@modifies {ModifiedType}"
)
'(
;; ("@modifies$" . typescript-jsdoc-tag)
;; ("@modifies {ModifiedType}" . typescript-jsdoc-tag)
;; ("{ModifiedType}" . typescript-jsdoc-type)
)))
(ert-deftest jsdoc/modifies-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @modifies tags and its alias."
(jsdoc-multiline-test
'(
"@modifies name0"
"@modifies {ModifiedType} and name1"
)
'(
;; ("@modifies name0" . typescript-jsdoc-tag)
;; ("name0" . font-lock-comment-face)
;; ("@modifies {ModifiedType} and name1" . typescript-jsdoc-tag)
;; ("{ModifiedType} and name1" . typescript-jsdoc-type)
;; ("and name1" . font-lock-comment-face)
;; ("name1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/modifies-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @modifies tags and its alias."
(jsdoc-multiline-test
'(
"@modifies"
)
'(
("@modifies$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/module-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @module tags and its alias."
(jsdoc-multiline-test
'(
"@module"
"@module ModuleName0"
"@module {ModuleType0}"
"@module {ModuleType1} ModuleName1"
)
'(
;; ("@module$" . typescript-jsdoc-tag)
("@module ModuleName0" . typescript-jsdoc-tag)
("ModuleName0" . typescript-jsdoc-value)
("@module {ModuleType0}" . typescript-jsdoc-tag)
;; ("{ModuleType0}" . typescript-jsdoc-type)
("@module {ModuleType1} ModuleName1" . typescript-jsdoc-tag)
;; ("{ModuleType1} ModuleName1" . typescript-jsdoc-type)
;; ("ModuleName1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/module-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @module tags and its alias."
(jsdoc-multiline-test
'(
"@module with multiple words0"
"@module {ModuleType} with multiple words1"
)
'(
("@module with multiple words0" . typescript-jsdoc-tag)
("with multiple words0" . typescript-jsdoc-value)
("multiple words0" . font-lock-comment-face)
("words0" . font-lock-comment-face)
("@module {ModuleType} with multiple words1" . typescript-jsdoc-tag)
;; ("{ModuleType} with multiple words1" . typescript-jsdoc-type)
;; ("with multiple words1" . typescript-jsdoc-value)
("multiple words1" . font-lock-comment-face)
("words1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/module-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @module tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/namespace-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @namespace tags and its alias."
(jsdoc-multiline-test
'(
"@namespace"
"@namespace Namespace0"
"@namespace {NamespaceType0}"
"@namespace {NamespaceType1} Namespace1"
)
'(
;; ("@namespace$" . typescript-jsdoc-tag)
("@namespace Namespace0" . typescript-jsdoc-tag)
("Namespace0" . typescript-jsdoc-value)
("@namespace {NamespaceType0}" . typescript-jsdoc-tag)
;; ("{NamespaceType0}" . typescript-jsdoc-type)
("@namespace {NamespaceType1} Namespace1" . typescript-jsdoc-tag)
;; ("{NamespaceType1} Namespace1" . typescript-jsdoc-type)
;; ("Namespace1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/namespace-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @namespace tags and its alias."
(jsdoc-multiline-test
'(
"@namespace with multiple words0"
"@namespace {NamespaceType} with multiple words1"
)
'(
("@namespace with multiple words0" . typescript-jsdoc-tag)
("with multiple words0" . typescript-jsdoc-value)
("multiple words0" . font-lock-comment-face)
("words0" . font-lock-comment-face)
("@namespace {NamespaceType} with multiple words1" . typescript-jsdoc-tag)
;; ("{NamespaceType} with multiple words1" . typescript-jsdoc-type)
;; ("with multiple words1" . typescript-jsdoc-value)
("multiple words1" . font-lock-comment-face)
("words1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/namespace-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @namespace tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/package-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @package tags and its alias."
(jsdoc-multiline-test
'(
"@package"
)
'(
("@package$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/package-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @package tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/package-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @package tags and its alias."
(jsdoc-multiline-test
'(
"@package invalid extra values"
"@package {InvalidType}"
)
'(
("@package invalid extra values" . typescript-jsdoc-tag)
("invalid extra values" . font-lock-comment-face)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@package {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/param-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @param tags and its alias."
(jsdoc-multiline-test
'(
"@param"
"@param {ParamType0}"
"@param paramName0"
"@param {ParamType1} paramName1"
"@param {ParamType2} paramName2 with paramDescription2"
"@arg"
"@arg {ArgType0}"
"@arg argName0"
"@arg {ArgType1} argName1"
"@arg {ArgType2} argName2 with argDescription2"
"@argument"
"@argument {ArgumentType0}"
"@argument argumentName0"
"@argument {ArgumentType1} argumentName1"
"@argument {ArgumentType2} argumentName2 with argumentDescription2"
)
'(
("@param$" . typescript-jsdoc-tag)
("@param {ParamType0}" . typescript-jsdoc-tag)
;; ("{ParamType0}" . typescript-jsdoc-type)
("@param paramName0" . typescript-jsdoc-tag)
("paramName0" . typescript-jsdoc-value)
("@param {ParamType1} paramName1" . typescript-jsdoc-tag)
("{ParamType1} paramName1" . typescript-jsdoc-type)
("paramName1" . typescript-jsdoc-value)
("@param {ParamType2} paramName2 with paramDescription2" . typescript-jsdoc-tag)
("{ParamType2} paramName2 with paramDescription2" . typescript-jsdoc-type)
("paramName2 with paramDescription2" . typescript-jsdoc-value)
("with paramDescription2" . font-lock-comment-face)
("paramDescription2" . font-lock-comment-face)
("@arg$" . typescript-jsdoc-tag)
("@arg {ArgType0}" . typescript-jsdoc-tag)
;; ("{ArgType0}" . typescript-jsdoc-type)
("@arg argName0" . typescript-jsdoc-tag)
("argName0" . typescript-jsdoc-value)
("@arg {ArgType1} argName1" . typescript-jsdoc-tag)
("{ArgType1} argName1" . typescript-jsdoc-type)
("argName1" . typescript-jsdoc-value)
("@arg {ArgType2} argName2 with argDescription2" . typescript-jsdoc-tag)
("{ArgType2} argName2 with argDescription2" . typescript-jsdoc-type)
("argName2 with argDescription2" . typescript-jsdoc-value)
("with argDescription2" . font-lock-comment-face)
("argDescription2" . font-lock-comment-face)
("@argument$" . typescript-jsdoc-tag)
("@argument {ArgumentType0}" . typescript-jsdoc-tag)
;; ("{ArgumentType0}" . typescript-jsdoc-type)
("@argument argumentName0" . typescript-jsdoc-tag)
("argumentName0" . typescript-jsdoc-value)
("@argument {ArgumentType1} argumentName1" . typescript-jsdoc-tag)
("{ArgumentType1} argumentName1" . typescript-jsdoc-type)
("argumentName1" . typescript-jsdoc-value)
("@argument {ArgumentType2} argumentName2 with argumentDescription2" . typescript-jsdoc-tag)
("{ArgumentType2} argumentName2 with argumentDescription2" . typescript-jsdoc-type)
("argumentName2 with argumentDescription2" . typescript-jsdoc-value)
("with argumentDescription2" . font-lock-comment-face)
("argumentDescription2" . font-lock-comment-face)
)))
(ert-deftest jsdoc/param-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @param tags and its alias."
(jsdoc-multiline-test
'(
"@param extra value0"
"@arg extra value1"
"@argument extra value2"
)
'(
("@param extra value0" . typescript-jsdoc-tag)
("extra value0" . typescript-jsdoc-value)
("value0" . font-lock-comment-face)
("@arg extra value1" . typescript-jsdoc-tag)
("extra value1" . typescript-jsdoc-value)
("value1" . font-lock-comment-face)
("@argument extra value2" . typescript-jsdoc-tag)
("extra value2" . typescript-jsdoc-value)
("value2" . font-lock-comment-face)
)))
(ert-deftest jsdoc/param-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @param tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/private-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @private tags and its alias."
(jsdoc-multiline-test
'(
"@private"
)
'(
("@private$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/private-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @private tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/private-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @private tags and its alias."
(jsdoc-multiline-test
'(
"@private invalid extra values"
"@private {InvalidType}"
)
'(
("@private invalid extra values" . typescript-jsdoc-tag)
("invalid extra values" . font-lock-comment-face)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@private {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/property-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @property tags and its alias."
(jsdoc-multiline-test
'(
"@property {PropertyType0}"
"@property propertyName0"
"@property {PropertyType1} propertyName1"
"@property {PropertyType2} propertyName2 with propertyDescription2"
"@prop"
"@prop {PropType0}"
"@prop propName0"
"@prop {PropType1} propName1"
"@prop {PropType2} propName2 with propDescription2"
)
'(
("@property {PropertyType0}" . typescript-jsdoc-tag)
;; ("{PropertyType0}" . typescript-jsdoc-type)
("@property propertyName0" . typescript-jsdoc-tag)
("propertyName0" . typescript-jsdoc-value)
("@property {PropertyType1} propertyName1" . typescript-jsdoc-tag)
("{PropertyType1} propertyName1" . typescript-jsdoc-type)
("propertyName1" . typescript-jsdoc-value)
("@property {PropertyType2} propertyName2 with propertyDescription2" . typescript-jsdoc-tag)
("{PropertyType2} propertyName2 with propertyDescription2" . typescript-jsdoc-type)
("propertyName2 with propertyDescription2" . typescript-jsdoc-value)
("with propertyDescription2" . font-lock-comment-face)
("propertyDescription2" . font-lock-comment-face)
("@prop {PropType0}" . typescript-jsdoc-tag)
;; ("{PropType0}" . typescript-jsdoc-type)
("@prop propName0" . typescript-jsdoc-tag)
("propName0" . typescript-jsdoc-value)
("@prop {PropType1} propName1" . typescript-jsdoc-tag)
("{PropType1} propName1" . typescript-jsdoc-type)
("propName1" . typescript-jsdoc-value)
("@prop {PropType2} propName2 with propDescription2" . typescript-jsdoc-tag)
("{PropType2} propName2 with propDescription2" . typescript-jsdoc-type)
("propName2 with propDescription2" . typescript-jsdoc-value)
("with propDescription2" . font-lock-comment-face)
("propDescription2" . font-lock-comment-face)
)))
(ert-deftest jsdoc/property-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @property tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/property-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @property tags and its alias."
(jsdoc-multiline-test
'(
"@property"
"@prop"
)
'(
;; ("@property$" . font-lock-comment-face)
;; ("@prop$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/protected-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @protected tags and its alias."
(jsdoc-multiline-test
'(
"@protected"
)
'(
("@protected$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/protected-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @protected tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/protected-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @protected tags and its alias."
(jsdoc-multiline-test
'(
"@protected invalid extra values"
"@protected {InvalidType}"
)
'(
("@protected invalid extra values" . typescript-jsdoc-tag)
("invalid extra values" . font-lock-comment-face)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@protected {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/public-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @public tags and its alias."
(jsdoc-multiline-test
'(
"@public"
)
'(
("@public$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/public-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @public tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/public-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @public tags and its alias."
(jsdoc-multiline-test
'(
"@public invalid extra values"
"@public {InvalidType}"
)
'(
("@public invalid extra values" . typescript-jsdoc-tag)
("invalid extra values" . font-lock-comment-face)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@public {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/readonly-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @readonly tags and its alias."
(jsdoc-multiline-test
'(
"@readonly"
)
'(
("@readonly$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/readonly-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @readonly tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/readonly-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @readonly tags and its alias."
(jsdoc-multiline-test
'(
"@readonly invalid extra values"
"@readonly {InvalidType}"
)
'(
("@readonly invalid extra values" . typescript-jsdoc-tag)
("invalid extra values" . font-lock-comment-face)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@readonly {InvalidType}" . typescript-jsdoc-tag)
("{InvalidType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/requires-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @requires tags and its alias."
(jsdoc-multiline-test
'(
"@requires SomeModuleName"
"@requires module:path/to/module"
"@requires {@link something}"
)
'(
("@requires SomeModuleName" . typescript-jsdoc-tag)
("SomeModuleName" . typescript-jsdoc-value)
("@requires module:path/to/module" . typescript-jsdoc-tag)
("module:path/to/module" . typescript-jsdoc-value)
("@requires {@link something}" . typescript-jsdoc-tag)
("{@link something}" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/requires-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @requires tags and its alias."
(jsdoc-multiline-test
'(
"@requires extra text0"
"@requires {RequiresType0}"
"@requires {RequiresType1} and text1"
)
'(
("@requires extra text0" . typescript-jsdoc-tag)
("extra text0" . typescript-jsdoc-value)
("text0" . font-lock-comment-face)
("@requires {RequiresType0}" . typescript-jsdoc-tag)
("{RequiresType0}" . typescript-jsdoc-value)
("@requires {RequiresType1} and text1" . typescript-jsdoc-tag)
("{RequiresType1} and text1" . typescript-jsdoc-value)
("and text1" . font-lock-comment-face)
("text1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/requires-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @requires tags and its alias."
(jsdoc-multiline-test
'(
"@requires"
)
'(
;; ("@requires$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/returns-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @returns tags and its alias."
(jsdoc-multiline-test
'(
"@returns description for returned value0"
"@returns {ReturnType1} description for returned value1"
"@return description for returned value2"
"@return {ReturnType3} description for returned value3"
)
'(
("@returns description for returned value0" . typescript-jsdoc-tag)
("description for returned value0" . font-lock-comment-face)
("for returned value0" . font-lock-comment-face)
("returned value0" . font-lock-comment-face)
("value0" . font-lock-comment-face)
("@returns {ReturnType1} description for returned value1" . typescript-jsdoc-tag)
("{ReturnType1} description for returned value1" . typescript-jsdoc-type)
("description for returned value1" . font-lock-comment-face)
("for returned value1" . font-lock-comment-face)
("returned value1" . font-lock-comment-face)
("value1" . font-lock-comment-face)
("@return description for returned value2" . typescript-jsdoc-tag)
("description for returned value2" . font-lock-comment-face)
("for returned value2" . font-lock-comment-face)
("returned value2" . font-lock-comment-face)
("value2" . font-lock-comment-face)
("@return {ReturnType3} description for returned value3" . typescript-jsdoc-tag)
("{ReturnType3} description for returned value3" . typescript-jsdoc-type)
("description for returned value3" . font-lock-comment-face)
("for returned value3" . font-lock-comment-face)
("returned value3" . font-lock-comment-face)
("value3" . font-lock-comment-face)
)))
(ert-deftest jsdoc/returns-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @returns tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/returns-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @returns tags and its alias."
(jsdoc-multiline-test
'(
"@returns"
"@return"
)
'(
;; ("@returns$" . font-lock-comment-face)
;; ("@return$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/see-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @see tags and its alias."
(jsdoc-multiline-test
'(
"@see someName.path"
"@see {@link something}"
"@see any other text"
)
'(
;; ("@see someName.path" . typescript-jsdoc-tag)
;; ("someName.path" . typescript-jsdoc-value)
;; ("@see {@link something}" . typescript-jsdoc-tag)
;; ("{@link something}" . typescript-jsdoc-value)
;; ("@see any other text" . typescript-jsdoc-tag)
;; ("any other text" . typescript-jsdoc-value)
;; ("other text" . typescript-jsdoc-value)
;; ("text" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/see-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @see tags and its alias."
(jsdoc-multiline-test
'(
"@see {SeeType0}"
"@see {SeeType1} and text1"
)
'(
;; ("@see {SeeType0}" . typescript-jsdoc-tag)
;; ("{SeeType0}" . typescript-jsdoc-value)
;; ("@see {SeeType1} and text1" . typescript-jsdoc-tag)
;; ("{SeeType1} and text1" . typescript-jsdoc-value)
;; ("and text1" . typescript-jsdoc-value)
;; ("text1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/see-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @see tags and its alias."
(jsdoc-multiline-test
'(
"@see"
)
'(
("@see$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/since-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @since tags and its alias."
(jsdoc-multiline-test
'(
"@since 1.0.1"
)
'(
("@since 1.0.1" . typescript-jsdoc-tag)
("1.0.1" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/since-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @since tags and its alias."
(jsdoc-multiline-test
'(
"@since some extra text0"
"@since {SinceType0}"
"@since {SinceType1} and text1"
)
'(
("@since some extra text0" . typescript-jsdoc-tag)
("some extra text0" . typescript-jsdoc-value)
("extra text0" . font-lock-comment-face)
("text0" . font-lock-comment-face)
("@since {SinceType0}" . typescript-jsdoc-tag)
("{SinceType0}" . typescript-jsdoc-value)
("@since {SinceType1} and text1" . typescript-jsdoc-tag)
("{SinceType1} and text1" . typescript-jsdoc-value)
("and text1" . font-lock-comment-face)
("text1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/since-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @since tags and its alias."
(jsdoc-multiline-test
'(
"@since"
)
'(
("@since$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/static-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @static tags and its alias."
(jsdoc-multiline-test
'(
"@static"
)
'(
("@static$" . typescript-jsdoc-tag)
)))
(ert-deftest jsdoc/static-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @static tags and its alias."
(jsdoc-multiline-test
'(
"@static extra values"
"@static {StaticType}"
)
'(
("@static extra values" . typescript-jsdoc-tag)
("extra values" . font-lock-comment-face)
("values" . font-lock-comment-face)
("@static {StaticType}" . typescript-jsdoc-tag)
("{StaticType}" . font-lock-comment-face)
)))
(ert-deftest jsdoc/static-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @static tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/summary-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @summary tags and its alias."
(jsdoc-multiline-test
'(
"@summary some summary text"
)
'(
("@summary some summary text" . typescript-jsdoc-tag)
("some summary text" . font-lock-comment-face)
("summary text" . font-lock-comment-face)
("text" . font-lock-comment-face)
)))
(ert-deftest jsdoc/summary-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @summary tags and its alias."
(jsdoc-multiline-test
'(
"@summary {SummaryType0}"
"@summary {SummaryType1} and text1"
)
'(
("@summary {SummaryType0}" . typescript-jsdoc-tag)
("{SummaryType0}" . font-lock-comment-face)
("@summary {SummaryType1} and text1" . typescript-jsdoc-tag)
("{SummaryType1} and text1" . font-lock-comment-face)
("and text1" . font-lock-comment-face)
("text1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/summary-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @summary tags and its alias."
(jsdoc-multiline-test
'(
"@summary"
)
'(
;; ("@summary$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/this-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @this tags and its alias."
(jsdoc-multiline-test
'(
"@this ClassForThis"
)
'(
("@this ClassForThis" . typescript-jsdoc-tag)
("ClassForThis" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/this-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @this tags and its alias."
(jsdoc-multiline-test
'(
"@this and multiple words0"
"@this {SummaryType0}"
"@this {SummaryType1} and multiple words1"
)
'(
("@this and multiple words0" . typescript-jsdoc-tag)
("and multiple words0" . typescript-jsdoc-value)
("multiple words0" . font-lock-comment-face)
("words0" . font-lock-comment-face)
("@this {SummaryType0}" . typescript-jsdoc-tag)
("{SummaryType0}" . typescript-jsdoc-value)
("@this {SummaryType1} and multiple words1" . typescript-jsdoc-tag)
("{SummaryType1} and multiple words1" . typescript-jsdoc-value)
("and multiple words1" . font-lock-comment-face)
("multiple words1" . font-lock-comment-face)
("words1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/this-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @this tags and its alias."
(jsdoc-multiline-test
'(
"@this"
)
'(
("@this$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/todo-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @todo tags and its alias."
(jsdoc-multiline-test
'(
"@todo todo things"
"@todo more things to do!"
)
'(
("@todo todo things" . typescript-jsdoc-tag)
("todo things" . font-lock-comment-face)
("things" . font-lock-comment-face)
("@todo more things to do!" . typescript-jsdoc-tag)
("more things to do!" . font-lock-comment-face)
("things to do!" . font-lock-comment-face)
("to do!" . font-lock-comment-face)
("do!" . font-lock-comment-face)
)))
(ert-deftest jsdoc/todo-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @todo tags and its alias."
(jsdoc-multiline-test
'(
"@todo {TodoType0}"
"@todo {TodoType1} and text1"
)
'(
("@todo {TodoType0}" . typescript-jsdoc-tag)
("{TodoType0}" . font-lock-comment-face)
("@todo {TodoType1} and text1" . typescript-jsdoc-tag)
("{TodoType1} and text1" . font-lock-comment-face)
("and text1" . font-lock-comment-face)
("text1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/todo-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @todo tags and its alias."
(jsdoc-multiline-test
'(
"@todo"
)
'(
;; ("@todo$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/throws-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @throws tags and its alias."
(jsdoc-multiline-test
'(
"@throws explanation for throws cases0"
"@throws {ThrowsType0}"
"@throws {ThrowsType1} explanation for throws cases1"
"@exception explanation for exception0"
"@exception {ExceptionType0}"
"@exception {ExceptionType1} explanation for exception1"
)
'(
("@throws explanation for throws cases0" . typescript-jsdoc-tag)
;; ("explanation for throws cases0" . font-lock-comment-face)
("for throws cases0" . font-lock-comment-face)
("throws cases0" . font-lock-comment-face)
("cases0" . font-lock-comment-face)
("@throws {ThrowsType0}" . typescript-jsdoc-tag)
;; ("{ThrowsType0}" . typescript-jsdoc-type)
("@throws {ThrowsType1} explanation for throws cases1" . typescript-jsdoc-tag)
;; ("{ThrowsType1} explanation for throws cases1" . typescript-jsdoc-type)
("explanation for throws cases1" . font-lock-comment-face)
("for throws cases1" . font-lock-comment-face)
("throws cases1" . font-lock-comment-face)
("cases1" . font-lock-comment-face)
("@exception explanation for exception0" . typescript-jsdoc-tag)
;; ("explanation for exception0" . font-lock-comment-face)
("for exception0" . font-lock-comment-face)
("exception0" . font-lock-comment-face)
("@exception {ExceptionType0}" . typescript-jsdoc-tag)
;; ("{ExceptionType0}" . typescript-jsdoc-type)
("@exception {ExceptionType1} explanation for exception1" . typescript-jsdoc-tag)
;; ("{ExceptionType1} explanation for exception1" . typescript-jsdoc-type)
("explanation for exception1" . font-lock-comment-face)
("for exception1" . font-lock-comment-face)
("exception1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/throws-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @throws tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/throws-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @throws tags and its alias."
(jsdoc-multiline-test
'(
"@throws"
"@exception"
)
'(
;; ("@throws$" . font-lock-comment-face)
;; ("@exception$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/tutorial-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @tutorial tags and its alias."
(jsdoc-multiline-test
'(
"@tutorial tutorial-file0"
)
'(
("@tutorial tutorial-file0" . typescript-jsdoc-tag)
;; ("tutorial-file0" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/tutorial-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @tutorial tags and its alias."
(jsdoc-multiline-test
'(
"@tutorial multiple words0"
"@tutorial {TutorialType0}"
"@tutorial {TutorialType1} multiple words1"
)
'(
("@tutorial multiple words0" . typescript-jsdoc-tag)
;; ("multiple words0" . typescript-jsdoc-value)
("words0" . font-lock-comment-face)
("@tutorial {TutorialType0}" . typescript-jsdoc-tag)
;; ("{TutorialType0}" . typescript-jsdoc-value)
("@tutorial {TutorialType1} multiple words1" . typescript-jsdoc-tag)
;; ("{TutorialType1} multiple words1" . typescript-jsdoc-value)
("multiple words1" . font-lock-comment-face)
("words1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/tutorial-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @tutorial tags and its alias."
(jsdoc-multiline-test
'(
"@tutorial"
)
'(
;; ("@tutorial$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/type-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @type tags and its alias."
(jsdoc-multiline-test
'(
"@type TypeOfSomething0"
"@type {TypeofSomething1}"
)
'(
("@type TypeOfSomething0" . typescript-jsdoc-tag)
;; ("TypeOfSomething0" . typescript-jsdoc-type)
("@type {TypeOfSomething1}" . typescript-jsdoc-tag)
("{TypeOfSomething1}" . typescript-jsdoc-type)
)))
(ert-deftest jsdoc/type-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @type tags and its alias."
(jsdoc-multiline-test
'(
"@type multiple words0"
"@type {Type0} multiple words1"
)
'(
("@type multiple words0" . typescript-jsdoc-tag)
;; ("multiple words0" . typescript-jsdoc-type)
("words0" . font-lock-comment-face)
("@type {Type0} multiple words1" . typescript-jsdoc-tag)
("{Type0} multiple words1" . typescript-jsdoc-type)
("multiple words1" . font-lock-comment-face)
("words1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/type-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @type tags and its alias."
(jsdoc-multiline-test
'(
"@type"
)
'(
;; ("@type$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/typedef-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @typedef tags and its alias."
(jsdoc-multiline-test
'(
"@typedef nameOfNewType0"
"@typedef namePath~OfNewType0"
"@typedef {TypeOfNewType0} nameOfNewType1"
"@typedef {TypeOfNewType1} namePath~OfNewType1"
"@callback nameOfNewCallback"
"@callback namePath~OfNewCallback"
)
'(
("@typedef nameOfNewType0" . typescript-jsdoc-tag)
("nameOfNewType0" . typescript-jsdoc-value)
("@typedef namePath~OfNewType0" . typescript-jsdoc-tag)
("namePath~OfNewType0" . typescript-jsdoc-value)
("OfNewType0" . typescript-jsdoc-value)
("@typedef {TypeOfNewType0} nameOfNewType1" . typescript-jsdoc-tag)
("{TypeOfNewType0} nameOfNewType1" . typescript-jsdoc-type)
("nameOfNewType1" . typescript-jsdoc-value)
("@typedef {TypeOfNewType1} namePath~OfNewType1" . typescript-jsdoc-tag)
("{TypeOfNewType1} namePath~OfNewType1" . typescript-jsdoc-type)
("namePath~OfNewType1" . typescript-jsdoc-value)
("OfNewType1" . typescript-jsdoc-value)
("@callback nameOfNewCallback" . typescript-jsdoc-tag)
("nameOfNewCallback" . typescript-jsdoc-value)
("@callback namePath~OfNewCallback" . typescript-jsdoc-tag)
("namePath~OfNewCallback" . typescript-jsdoc-value)
("OfNewCallback" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/typedef-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @typedef tags and its alias."
(jsdoc-multiline-test
'(
"@typedef"
"@typedef multiple words0"
"@typedef {TypeOfNewType0}"
"@typedef {TypeOfNewType1} multiple words1"
"@callback"
"@callback multiple words for callback0"
"@callback {CallbackType0}"
"@callback {CallbackType1} nameOfNewCallback"
"@callback {CallbackType2} namePath~OfNewCallback"
"@callback {CallbackType3} multiple words for callback1"
)
'(
("@typedef$" . typescript-jsdoc-tag)
("@typedef multiple words0" . typescript-jsdoc-tag)
("multiple words0" . typescript-jsdoc-value)
("words0" . font-lock-comment-face)
("@typedef {TypeOfNewType0}" . typescript-jsdoc-tag)
;; ("{TypeOfNewType0}" . typescript-jsdoc-type)
("@typedef {TypeOfNewType1} multiple words1" . typescript-jsdoc-tag)
("{TypeOfNewType1} multiple words1" . typescript-jsdoc-type)
("multiple words1" . typescript-jsdoc-value)
("words1" . font-lock-comment-face)
;; ("@callback$" . typescript-jsdoc-tag)
("@callback multiple words for callback0" . typescript-jsdoc-tag)
("multiple words for callback0" . typescript-jsdoc-value)
("words for callback0" . font-lock-comment-face)
("for callback0" . font-lock-comment-face)
("callback0" . font-lock-comment-face)
("@callback {CallbackType0}" . typescript-jsdoc-tag)
;; ("{CallbackType0}" . typescript-jsdoc-type)
("@callback {CallbackType1} nameOfNewCallback" . typescript-jsdoc-tag)
;; ("{CallbackType1} nameOfNewCallback" . typescript-jsdoc-type)
;; ("nameOfNewCallback" . typescript-jsdoc-value)
("@callback {CallbackType2} namePath~OfNewCallback" . typescript-jsdoc-tag)
;; ("{CallbackType2} namePath~OfNewCallback" . typescript-jsdoc-type)
;; ("namePath~OfNewCallback" . typescript-jsdoc-value)
;; ("OfNewCallback" . typescript-jsdoc-value)
("@callback {CallbackType3} multiple words for callback1" . typescript-jsdoc-tag)
;; ("{CallbackType3} multiple words for callback1" . typescript-jsdoc-type)
;; ("multiple words for callback1" . typescript-jsdoc-value)
("words for callback1" . font-lock-comment-face)
("for callback1" . font-lock-comment-face)
("callback1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/typedef-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @typedef tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/variation-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @variation tags and its alias."
(jsdoc-multiline-test
'(
"@variation 0"
"@variation (1)"
)
'(
("@variation 0" . typescript-jsdoc-tag)
("0" . typescript-jsdoc-value)
("@variation (1)" . typescript-jsdoc-tag)
("(1)" . typescript-jsdoc-value)
("1)" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/variation-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @variation tags and its alias."
(jsdoc-multiline-test
'(
"@variation multiple words0"
"@variation {VariationType0}"
"@variation {VariationType1} multiple words1"
)
'(
("@variation multiple words0" . typescript-jsdoc-tag)
("multiple words0" . typescript-jsdoc-value)
("words0" . font-lock-comment-face)
("@variation {VariationType0}" . typescript-jsdoc-tag)
("{VariationType0}" . typescript-jsdoc-value)
("@variation {VariationType1} multiple words1" . typescript-jsdoc-tag)
("{VariationType1} multiple words1" . typescript-jsdoc-value)
("multiple words1" . font-lock-comment-face)
("words1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/variation-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @variation tags and its alias."
(jsdoc-multiline-test
'(
"@variation"
)
'(
("@variation$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/version-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @version tags and its alias."
(jsdoc-multiline-test
'(
"@version 1.2.3"
"@version (4.7.1)"
)
'(
("@version 1.2.3" . typescript-jsdoc-tag)
("1.2.3" . typescript-jsdoc-value)
("2.3" . typescript-jsdoc-value)
("3" . typescript-jsdoc-value)
("@version (4.7.1)" . typescript-jsdoc-tag)
("(4.7.1)" . typescript-jsdoc-value)
("7.1)" . typescript-jsdoc-value)
("1)" . typescript-jsdoc-value)
)))
(ert-deftest jsdoc/version-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @version tags and its alias."
(jsdoc-multiline-test
'(
"@version multiple words0"
"@version {VersionType0}"
"@version {VersionType1} multiple words1"
)
'(
("@version multiple words0" . typescript-jsdoc-tag)
("multiple words0" . typescript-jsdoc-value)
("words0" . font-lock-comment-face)
("@version {VersionType0}" . typescript-jsdoc-tag)
("{VersionType0}" . typescript-jsdoc-value)
("@version {VersionType1} multiple words1" . typescript-jsdoc-tag)
("{VersionType1} multiple words1" . typescript-jsdoc-value)
("multiple words1" . font-lock-comment-face)
("words1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/version-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @version tags and its alias."
(jsdoc-multiline-test
'(
"@version"
)
'(
("@version$" . font-lock-comment-face)
)))
(ert-deftest jsdoc/yields-tag-in-multiline-doc-comment-with-meaningful-cases ()
"Test for meaningful and valid usage of @yields tags and its alias."
(jsdoc-multiline-test
'(
"@yields Text for yields0"
"@yields {YieldsType0}"
"@yields {YieldsType1} Text for yields1"
"@yield Text for yield0"
"@yield {YieldType0}"
"@yield {YieldType1} Text for yield1"
)
'(
("@yields Text for yields0" . typescript-jsdoc-tag)
("Text for yields0" . font-lock-comment-face)
("for yields0" . font-lock-comment-face)
("yields0" . font-lock-comment-face)
("@yields {YieldsType0}" . typescript-jsdoc-tag)
("{YieldsType0}" . typescript-jsdoc-type)
("@yields {YieldsType1} Text for yields1" . typescript-jsdoc-tag)
("{YieldsType1} Text for yields1" . typescript-jsdoc-type)
("Text for yields1" . font-lock-comment-face)
("for yields1" . font-lock-comment-face)
("yields1" . font-lock-comment-face)
("@yield Text for yield0" . typescript-jsdoc-tag)
("Text for yield0" . font-lock-comment-face)
("for yield0" . font-lock-comment-face)
("yield0" . font-lock-comment-face)
("@yield {YieldType0}" . typescript-jsdoc-tag)
("{YieldType0}" . typescript-jsdoc-type)
("@yield {YieldType1} Text for yield1" . typescript-jsdoc-tag)
("{YieldType1} Text for yield1" . typescript-jsdoc-type)
("Text for yield1" . font-lock-comment-face)
("for yield1" . font-lock-comment-face)
("yield1" . font-lock-comment-face)
)))
(ert-deftest jsdoc/yields-tag-in-multiline-doc-comment-with-meaningless-cases ()
"Test for meaningless though valid usage of @yields tags and its alias."
(jsdoc-multiline-test
'(
)
'(
)))
(ert-deftest jsdoc/yields-tag-in-multiline-doc-comment-with-invalid-cases ()
"Test for invalid usage of @yields tags and its alias."
(jsdoc-multiline-test
'(
"@yields"
)
'(
;; ("@yields$" . font-lock-comment-face)
)))
;; Do we need to add closure tags?
;; See https://github.com/jsdoc3/jsdoc/blob/b21427343c7294bbf1f14c718a390f3e955e37cb/lib/jsdoc/tag/dictionary/definitions.js#L870-L1031
(provide 'typescript-mode-jsdoc-tests)
;;; typescript-mode-jsdoc-tests.el ends here
================================================
FILE: typescript-mode-lexical-binding-tests.el
================================================
;; -*- lexical-binding: t -*-
;;; typescript-mode-lexical-binding-tests --- This file contains test for typescript-mode.el under enabled lexical-binding
;;; Commentary:
;; To know how to run the tests, see typescript-mode-tests.el
(require 'ert)
;; reload typescript-mode with lexical-binding enabled
(with-temp-buffer
(insert-file-contents "typescript-mode.el")
(ignore-errors
(while (setq sexp (read (current-buffer)))
(eval sexp t))))
(require 'typescript-mode-test-utilities)
(ert-deftest lexical-binding--indentation-does-not-throw-error ()
(with-temp-buffer
(insert-file-contents "test-files/indentation-reference-document.ts")
(typescript-mode)
(goto-line 2)
(typescript-indent-line)))
(provide 'typescript-mode-lexical-binding-tests)
================================================
FILE: typescript-mode-test-utilities.el
================================================
;;; typescript-mode-test-utilities --- This file contains test utilities for typescript-mode.el
;;; Commentary:
;; See typescript-mode-tests.el and typescript-mode-jsdoc-tests.el
;;; Code:
(require 'ert)
(require 'typescript-mode)
;; Adapted from jdee-mode's test suite.
(defmacro test-with-temp-buffer (content &rest body)
"Fill a temporary buffer with `CONTENT' and eval `BODY' in it."
(declare (debug t)
(indent 1))
`(with-temp-buffer
(insert ,content)
(typescript-mode)
(goto-char (point-min))
;; We need this so that tests that simulate user actions operate on the right buffer.
(switch-to-buffer (current-buffer))
,@body))
(defmacro test-with-fontified-buffer (content &rest body)
"Fill a temporary buffer with `CONTENT' and eval `BODY' in it."
(declare (debug t)
(indent 1))
`(test-with-temp-buffer
,content
(font-lock-ensure (point-min) (point-max))
,@body))
(defun get-face-at (loc)
"Get the face at `LOC'.
If it is not a number, then we `re-search-forward' with `LOC'
as the search pattern."
(when (not (numberp loc))
(save-excursion
(re-search-forward loc)
(setq loc (match-beginning 0))))
(get-text-property loc 'face))
(defun font-lock-test (contents expected)
"Perform a test on our template.
`CONTENTS' is the string to put in the temporary buffer.
`EXPECTED' is the expected results.
It should be a list of (LOCATION . FACE) pairs, where
LOCATION can be either a single location, or list of locations,
that are all expected to have the same face."
(test-with-fontified-buffer
contents
;; Make sure our propertize function has been applied to the whole
;; buffer.
(syntax-propertize (point-max))
(dolist (spec expected)
(if (listp (car spec))
(dolist (source (car spec))
(should (eq (get-face-at source) (cdr spec))))
(should (eq (get-face-at (car spec)) (cdr spec)))))))
(provide 'typescript-mode-test-utilities)
;;; typescript-mode-test-utilities.el ends here
================================================
FILE: typescript-mode-tests.el
================================================
;;; typescript-mode-tests --- This file contains automated tests for typescript-mode.el
;;; Commentary:
;; Run tests using (ert-run-tests-interactively t).
;;; Code:
(require 'ert)
(require 'typescript-mode)
(require 'cl-lib)
(require 'typescript-mode-test-utilities)
(require 'typescript-mode-general-tests)
(require 'typescript-mode-jsdoc-tests)
(require 'typescript-mode-lexical-binding-tests)
(provide 'typescript-mode-tests)
;;; typescript-mode-tests.el ends here
================================================
FILE: typescript-mode.el
================================================
;;; typescript-mode.el --- Major mode for editing typescript -*- lexical-binding: t -*-
;; -----------------------------------------------------------------------------------
;; TypeScript support for Emacs
;; Unmodified original sourve available at http://www.karllandstrom.se/downloads/emacs/javascript.el
;; Copyright (c) 2008-2025 Free Software Foundation
;; Portions Copyright (C) Microsoft Open Technologies, Inc. All rights reserved.
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see .
;; -------------------------------------------------------------------------------------------
;; URL: http://github.com/ananthakumaran/typescript.el
;; Version: 0.4
;; Keywords: typescript languages
;; Package-Requires: ((emacs "24.3"))
;; This file is not part of GNU Emacs.
;;; Commentary:
;; This is based on Karl Landstrom's barebones typescript-mode. This
;; is much more robust and works with cc-mode's comment filling
;; (mostly).
;; The modifications to the original javascript.el mode mainly consisted in
;; replacing "javascript" with "typescript"
;;
;; The main features of this typescript mode are syntactic
;; highlighting (enabled with `font-lock-mode' or
;; `global-font-lock-mode'), automatic indentation and filling of
;; comments.
;;
;;
;; General Remarks:
;;
;; XXX: This mode assumes that block comments are not nested inside block
;; XXX: comments
;;
;; Exported names start with "typescript-"; private names start with
;; "typescript--".
;;; Code:
(eval-and-compile
(require 'compile)
(require 'cc-mode)
(require 'font-lock)
(require 'rx)
(require 'newcomment))
(eval-when-compile
(require 'cl-lib))
;;; Constants
(defconst typescript--type-name-re "\\(?:[A-Z][A-Za-z0-9]+\\.\\)\\{0,\\}\\(?:[A-Z][A-Za-z0-9]+\\)"
"Regexp matching a conventional TypeScript type-name. Must start with upper-case letter!")
(defconst typescript--name-start-re "[a-zA-Z_$]"
"Regexp matching the start of a typescript identifier, without grouping.")
(defconst typescript--name-re (concat typescript--name-start-re
"\\(?:\\s_\\|\\sw\\)*")
"Regexp matching a typescript identifier, without grouping.")
(defconst typescript--objfield-re (concat typescript--name-re ":")
"Regexp matching the start of a typescript object field.")
(defconst typescript--dotted-name-re
(concat typescript--name-re "\\(?:\\." typescript--name-re "\\)*")
"Regexp matching a dot-separated sequence of typescript names.")
(defconst typescript--plain-method-re
(concat "^\\s-*?\\(" typescript--dotted-name-re "\\)\\.prototype"
"\\.\\(" typescript--name-re "\\)\\s-*?=\\s-*?\\(function\\)\\_>")
"Regexp matching an explicit typescript prototype \"method\" declaration.
Group 1 is a (possibly-dotted) class name, group 2 is a method name,
and group 3 is the 'function' keyword.")
(defconst typescript--plain-class-re
(concat "^\\s-*\\(" typescript--dotted-name-re "\\)\\.prototype"
"\\s-*=\\s-*{")
"Regexp matching a typescript explicit prototype \"class\" declaration.
An example of this is \"Class.prototype = { method1: ...}\".")
(defconst typescript--module-declaration-re
"^\\s-*\\(?:declare\\|\\(?:export\\(?:\\s-+default\\)?\\)\\)?"
"Regexp matching ambient declaration modifier or export declaration.")
;; var NewClass = BaseClass.extend(
(defconst typescript--mp-class-decl-re
(concat "^\\s-*var\\s-+"
"\\(" typescript--name-re "\\)"
"\\s-*=\\s-*"
"\\(" typescript--dotted-name-re
"\\)\\.extend\\(?:Final\\)?\\s-*(\\s-*{?\\s-*$"))
;; var NewClass = Class.create()
(defconst typescript--prototype-obsolete-class-decl-re
(concat "^\\s-*\\(?:var\\s-+\\)?"
"\\(" typescript--dotted-name-re "\\)"
"\\s-*=\\s-*Class\\.create()"))
(defconst typescript--prototype-objextend-class-decl-re-1
(concat "^\\s-*Object\\.extend\\s-*("
"\\(" typescript--dotted-name-re "\\)"
"\\s-*,\\s-*{"))
(defconst typescript--prototype-objextend-class-decl-re-2
(concat "^\\s-*\\(?:var\\s-+\\)?"
"\\(" typescript--dotted-name-re "\\)"
"\\s-*=\\s-*Object\\.extend\\s-*\("))
;; var NewClass = Class.create({
(defconst typescript--prototype-class-decl-re
(concat "^\\s-*\\(?:var\\s-+\\)?"
"\\(" typescript--name-re "\\)"
"\\s-*=\\s-*Class\\.create\\s-*(\\s-*"
"\\(?:\\(" typescript--dotted-name-re "\\)\\s-*,\\s-*\\)?{?"))
;; Parent class name(s) (yes, multiple inheritance in typescript) are
;; matched with dedicated font-lock matchers
(defconst typescript--dojo-class-decl-re
(concat "^\\s-*dojo\\.declare\\s-*(\"\\(" typescript--dotted-name-re "\\)"))
(defconst typescript--exttypescript-class-decl-re-1
(concat "^\\s-*Ext\\.extend\\s-*("
"\\s-*\\(" typescript--dotted-name-re "\\)"
"\\s-*,\\s-*\\(" typescript--dotted-name-re "\\)")
"Regexp matching an ExtTYPESCRIPT class declaration (style 1).")
(defconst typescript--exttypescript-class-decl-re-2
(concat "^\\s-*\\(?:var\\s-+\\)?"
"\\(" typescript--name-re "\\)"
"\\s-*=\\s-*Ext\\.extend\\s-*(\\s-*"
"\\(" typescript--dotted-name-re "\\)")
"Regexp matching an ExtTYPESCRIPT class declaration (style 2).")
(defconst typescript--mochikit-class-re
(concat "^\\s-*MochiKit\\.Base\\.update\\s-*(\\s-*"
"\\(" typescript--dotted-name-re "\\)")
"Regexp matching a MochiKit class declaration.")
(defconst typescript--dummy-class-style
'(:name "[Automatically Generated Class]"))
(defconst typescript--class-styles
`((:name "Plain"
:class-decl ,typescript--plain-class-re
:prototype t
:contexts (toplevel)
:framework typescript)
(:name "MochiKit"
:class-decl ,typescript--mochikit-class-re
:prototype t
:contexts (toplevel)
:framework mochikit)
(:name "Prototype (Obsolete)"
:class-decl ,typescript--prototype-obsolete-class-decl-re
:contexts (toplevel)
:framework prototype)
(:name "Prototype (Modern)"
:class-decl ,typescript--prototype-class-decl-re
:contexts (toplevel)
:framework prototype)
(:name "Prototype (Object.extend)"
:class-decl ,typescript--prototype-objextend-class-decl-re-1
:prototype t
:contexts (toplevel)
:framework prototype)
(:name "Prototype (Object.extend) 2"
:class-decl ,typescript--prototype-objextend-class-decl-re-2
:prototype t
:contexts (toplevel)
:framework prototype)
(:name "Dojo"
:class-decl ,typescript--dojo-class-decl-re
:contexts (toplevel)
:framework dojo)
(:name "ExtTYPESCRIPT (style 1)"
:class-decl ,typescript--exttypescript-class-decl-re-1
:prototype t
:contexts (toplevel)
:framework exttypescript)
(:name "ExtTYPESCRIPT (style 2)"
:class-decl ,typescript--exttypescript-class-decl-re-2
:contexts (toplevel)
:framework exttypescript)
(:name "Merrill Press"
:class-decl ,typescript--mp-class-decl-re
:contexts (toplevel)
:framework merrillpress))
"List of typescript class definition styles.
A class definition style is a plist with the following keys:
:name is a human-readable name of the class type
:class-decl is a regular expression giving the start of the
class. Its first group must match the name of its class. If there
is a parent class, the second group should match, and it should be
the name of the class.
If :prototype is present and non-nil, the parser will merge
declarations for this constructs with others at the same lexical
level that have the same name. Otherwise, multiple definitions
will create multiple top-level entries. Don't use :prototype
unnecessarily: it has an associated cost in performance.
If :strip-prototype is present and non-nil, then if the class
name as matched contains")
(defconst typescript--available-frameworks
(cl-loop with available-frameworks
for style in typescript--class-styles
for framework = (plist-get style :framework)
unless (memq framework available-frameworks)
collect framework into available-frameworks
finally return available-frameworks)
"List of available typescript frameworks symbols.")
(defconst typescript--function-heading-1-re
(concat
typescript--module-declaration-re
"\\s-*function\\s-+\\(" typescript--name-re "\\)")
"Regexp matching the start of a typescript function header.
Match group 1 is the name of the function.")
(defconst typescript--function-heading-2-re
(concat
"^\\s-*\\(" typescript--name-re "\\)\\s-*:\\s-*function\\_>")
"Regexp matching the start of a function entry in an associative array.
Match group 1 is the name of the function.")
(defconst typescript--function-heading-3-re
(concat
"^\\s-*\\(?:var\\s-+\\)?\\(" typescript--dotted-name-re "\\)"
"\\s-*=\\s-*function\\_>")
"Regexp matching a line in the typescript form \"var MUMBLE = function\".
Match group 1 is MUMBLE.")
(defun typescript--regexp-opt-symbol (list)
"Like `regexp-opt', but surround the result with `\\\\_<' and `\\\\_>'."
(concat "\\_<" (regexp-opt list t) "\\_>"))
(defconst typescript--keyword-re
(typescript--regexp-opt-symbol
'("abstract" "any" "as" "async" "await" "boolean" "bigint" "break" "case" "catch" "class" "const"
"constructor" "continue" "debugger" "declare" "default" "delete" "do" "else"
"enum" "export" "extends" "extern" "false" "finally" "for"
"function" "from" "get" "goto" "if" "implements" "import" "in" "infer" "instanceof"
"interface" "keyof" "let" "module" "namespace" "never" "new" "null" "number" "object" "of"
"override" "private" "protected" "public" "readonly" "return" "satisfies" "set" "static"
"string" "super" "switch" "this" "throw" "true"
"try" "type" "typeof" "unknown" "var" "void"
"while")) ; yield is handled separately
"Regexp matching any typescript keyword.")
(defconst typescript--basic-type-re
(typescript--regexp-opt-symbol
'("any" "bool" "boolean" "bigint" "never" "number" "string" "unknown" "void"))
"Regular expression matching any predefined type in typescript.")
(defconst typescript--access-modifier-re
(typescript--regexp-opt-symbol
'("private" "protected" "public" "readonly" "static" "extends" "implements"))
"Regular expression matching access modifiers.")
(defconst typescript--decorator-re
(concat "\\(@" typescript--name-re "\\)"))
(defconst typescript--constant-re
(typescript--regexp-opt-symbol '("false" "null" "undefined"
"Infinity" "NaN"
"true" "arguments" "this"))
"Regular expression matching any future reserved words in typescript.")
(defconst typescript--builtin-re
(typescript--regexp-opt-symbol
'("console"))
"Regular expression matching builtins.")
(defconst typescript--function-call-re "\\(\\(?:\\w\\|\\s_\\)+\\)\\(<.+>\\)?\s*("
"Regular expression matching function calls.")
(defconst typescript--font-lock-keywords-1
(list
"\\_"
(list typescript--function-heading-1-re 1 font-lock-function-name-face)
(list typescript--function-heading-2-re 1 font-lock-function-name-face))
"Level one font lock keywords for `typescript-mode'.")
(defconst typescript--font-lock-keywords-2
(append typescript--font-lock-keywords-1
`((,typescript--constant-re (0 'font-lock-constant-face))
(,typescript--basic-type-re (0 'font-lock-type-face))
(,typescript--keyword-re (1 'font-lock-keyword-face))
("\\_"
("\\s-+\\(each\\)\\_>" nil nil
(1 'font-lock-keyword-face)))
("\\_\\)" (0 'font-lock-keyword-face))))
"Level two font lock keywords for `typescript-mode'.")
;; typescript--pitem is the basic building block of the lexical
;; database. When one refers to a real part of the buffer, the region
;; of text to which it refers is split into a conceptual header and
;; body. Consider the (very short) block described by a hypothetical
;; typescript--pitem:
;;
;; function foo(a,b,c) { return 42; }
;; ^ ^ ^
;; | | |
;; +- h-begin +- h-end +- b-end
;;
;; (Remember that these are buffer positions, and therefore point
;; between characters, not at them. An arrow drawn to a character
;; indicates the corresponding position is between that character and
;; the one immediately preceding it.)
;;
;; The header is the region of text [h-begin, h-end], and is
;; the text needed to unambiguously recognize the start of the
;; construct. If the entire header is not present, the construct is
;; not recognized at all. No other pitems may be nested inside the
;; header.
;;
;; The body is the region [h-end, b-end]. It may contain nested
;; typescript--pitem instances. The body of a pitem may be empty: in
;; that case, b-end is equal to header-end.
;;
;; The three points obey the following relationship:
;;
;; h-begin < h-end <= b-end
;;
;; We put a text property in the buffer on the character *before*
;; h-end, and if we see it, on the character *before* b-end.
;;
;; The text property for h-end, typescript--pstate, is actually a list
;; of all typescript--pitem instances open after the marked character.
;;
;; The text property for b-end, typescript--pend, is simply the
;; typescript--pitem that ends after the marked character. (Because
;; pitems always end when the paren-depth drops below a critical
;; value, and because we can only drop one level per character, only
;; one pitem may end at a given character.)
;;
;; In the structure below, we only store h-begin and (sometimes)
;; b-end. We can trivially and quickly find h-end by going to h-begin
;; and searching for an typescript--pstate text property. Since no other
;; typescript--pitem instances can be nested inside the header of a
;; pitem, the location after the character with this text property
;; must be h-end.
;;
;; typescript--pitem instances are never modified (with the exception
;; of the b-end field). Instead, modified copies are added at subseqnce parse points.
;; (The exception for b-end and its caveats is described below.)
;;
(cl-defstruct (typescript--pitem (:type list))
;; IMPORTANT: Do not alter the position of fields within the list.
;; Various bits of code depend on their positions, particularly
;; anything that manipulates the list of children.
;; List of children inside this pitem's body
(children nil :read-only t)
;; When we reach this paren depth after h-end, the pitem ends
(paren-depth nil :read-only t)
;; Symbol or class-style plist if this is a class
(type nil :read-only t)
;; See above
(h-begin nil :read-only t)
;; List of strings giving the parts of the name of this pitem (e.g.,
;; '("MyClass" "myMethod"), or t if this pitem is anonymous
(name nil :read-only t)
;; THIS FIELD IS MUTATED, and its value is shared by all copies of
;; this pitem: when we copy-and-modify pitem instances, we share
;; their tail structures, so all the copies actually have the same
;; terminating cons cell. We modify that shared cons cell directly.
;;
;; The field value is either a number (buffer location) or nil if
;; unknown.
;;
;; If the field's value is greater than `typescript--cache-end', the
;; value is stale and must be treated as if it were nil. Conversely,
;; if this field is nil, it is guaranteed that this pitem is open up
;; to at least `typescript--cache-end'. (This property is handy when
;; computing whether we're inside a given pitem.)
;;
(b-end nil))
;; The pitem we start parsing with.
(defconst typescript--initial-pitem
(make-typescript--pitem
:paren-depth most-negative-fixnum
:type 'toplevel))
;; When we say "jsdoc" here, we mean "jsdoc 3". There exist multiple dialects of
;; "jsdoc documentation".
;; Note that all typedoc/jsdoc regexp by themselves would match occurrences that appear outside
;; documentation comments. The logic that uses these regexps must guard against it.
(defconst typescript-typedoc-link-tag-regexp
"\\[\\[.*?\\]\\]"
"Matches a typedoc link.")
(defconst typescript-typedoc-literal-markup-regexp
"\\(`+\\).*?\\1"
"Matches a typedoc keyword markup.")
(defconst typescript-jsdoc-before-tag-regexp
"\\(?:^\\s-*\\*+\\|/\\*\\*\\)\\s-*"
"Matches everything we allow before the @ of a jsdoc tag.")
;; This was taken from js2-mode.
(defconst typescript-jsdoc-param-tag-regexp
(concat typescript-jsdoc-before-tag-regexp
"\\(@"
(regexp-opt
'("arg"
"argument"
"param"
"prop"
"property"
"typedef"))
"\\)"
"\\s-*\\({[^}]+}\\)?" ; optional type
"\\s-*\\[?\\([[:alnum:]_$\.]+\\)?\\]?" ; name
"\\_>")
"Matches jsdoc tags with optional type and optional param name.")
;; This was taken from js2-mode.
;; and extended with tags in http://usejsdoc.org/
(defconst typescript-jsdoc-typed-tag-regexp
(concat typescript-jsdoc-before-tag-regexp
"\\(@"
(regexp-opt
'("enum"
"extends"
"field"
"id"
"implements"
"lends"
"mods"
"requires"
"return"
"returns"
"throw"
"throws"
"type"
"yield"
"yields"))
"\\)\\s-*\\({[^}]+}\\)?")
"Matches jsdoc tags with optional type.")
;; This was taken from js2-mode.
;; and extended with tags in http://usejsdoc.org/
(defconst typescript-jsdoc-arg-tag-regexp
(concat typescript-jsdoc-before-tag-regexp
"\\(@"
(regexp-opt
'("access"
"alias"
"augments"
"base"
"borrows"
"bug"
"callback"
"config"
"default"
"define"
"emits"
"exception"
"extends"
"external"
"fires"
"func"
"function"
"host"
"kind"
"listens"
"member"
"memberof"
"method"
"mixes"
"module"
"name"
"namespace"
"requires"
"since"
"suppress"
"this"
"throws"
"var"
"variation"
"version"))
"\\)\\s-+\\([^ \t]+\\)")
"Matches jsdoc tags with a single argument.")
;; This was taken from js2-mode
;; and extended with tags in http://usejsdoc.org/
(defconst typescript-jsdoc-empty-tag-regexp
(concat typescript-jsdoc-before-tag-regexp
"\\(@"
(regexp-opt
'("abstract"
"addon"
"async"
"author"
"class"
"classdesc"
"const"
"constant"
"constructor"
"constructs"
"copyright"
"default"
"defaultvalue"
"deprecated"
"desc"
"description"
"event"
"example"
"exec"
"export"
"exports"
"file"
"fileoverview"
"final"
"func"
"function"
"generator"
"global"
"hidden"
"hideconstructor"
"ignore"
"implicitcast"
"inheritdoc"
"inner"
"instance"
"interface"
"license"
"method"
"mixin"
"noalias"
"noshadow"
"notypecheck"
"override"
"overview"
"owner"
"package"
"preserve"
"preservetry"
"private"
"protected"
"public"
"readonly"
"static"
"summary"
"supported"
"todo"
"tutorial"
"virtual"))
"\\)\\s-*")
"Matches empty jsdoc tags.")
;; Note that this regexp by itself would match tslint flags that appear inside
;; strings. The logic using this regexp must guard against it.
(defconst typescript-tslint-flag-regexp
"\\(?://\\|/\\*\\)\\s-*\\(tslint:.*?\\)\\(?:\\*/\\|$\\)"
"Matches tslint flags.")
;;; Faces
(defface typescript-jsdoc-tag
'((t :foreground "SlateGray"))
"Face used to highlight @whatever tags in jsdoc comments."
:group 'typescript)
(defface typescript-jsdoc-type
'((t :foreground "SteelBlue"))
"Face used to highlight {FooBar} types in jsdoc comments."
:group 'typescript)
(defface typescript-jsdoc-value
'((t :foreground "gold4"))
"Face used to highlight tag values in jsdoc comments."
:group 'typescript)
(defface typescript-access-modifier-face
'((t (:inherit font-lock-keyword-face)))
"Face used to highlight access modifiers."
:group 'typescript)
(defface typescript-this-face
'((t (:inherit font-lock-keyword-face)))
"Face used to highlight 'this' keyword."
:group 'typescript)
(defface typescript-primitive-face
'((t (:inherit font-lock-keyword-face)))
"Face used to highlight builtin types."
:group 'typescript)
;;; User Customization
(defgroup typescript nil
"Customization variables for typescript mode."
:tag "typescript"
:group 'languages)
(defcustom typescript-indent-level 4
"Number of spaces for each indentation step in `typescript-mode'."
:type 'integer
:safe 'integerp
:group 'typescript)
;;;###autoload(put 'typescript-indent-level 'safe-local-variable #'integerp)
(defcustom typescript-expr-indent-offset 0
"Number of additional spaces used for indentation of continued expressions.
The value must be no less than minus `typescript-indent-level'."
:type 'integer
:safe 'integerp
:group 'typescript)
(defcustom typescript-indent-switch-clauses t
"Enable indenting of switch case and default clauses to
replicate tsserver behaviour. Indent level is taken to be
`typescript-indent-level'."
:type 'boolean
:group 'typescript)
(defcustom typescript-indent-list-items t
"Enable indenting of list items, useful for certain code styles."
:type 'boolean
:group 'typescript)
(defcustom typescript-auto-indent-flag t
"Whether to automatically indent when typing punctuation characters.
If non-nil, the characters {}();,: also indent the current line
in typescript mode."
:type 'boolean
:group 'typescript)
(defcustom typescript-flat-functions nil
"Treat nested functions as top-level functions in `typescript-mode'.
This applies to function movement, marking, and so on."
:type 'boolean
:group 'typescript)
(defcustom typescript-comment-lineup-func #'c-lineup-C-comments
"Lineup function for `cc-mode-style', for C comments in `typescript-mode'."
:type 'function
:group 'typescript)
(defcustom typescript-enabled-frameworks typescript--available-frameworks
"Frameworks recognized by `typescript-mode'.
To improve performance, you may turn off some frameworks you
seldom use, either globally or on a per-buffer basis."
:type (cons 'set (mapcar (lambda (x)
(list 'const x))
typescript--available-frameworks))
:group 'typescript)
(defcustom typescript-mode-hook nil
"*Hook called by `typescript-mode'."
:type 'hook
:group 'typescript)
(defcustom typescript-autoconvert-to-template-flag nil
"Non-nil means automatically convert plain strings to templates.
When the flag is non-nil the `typescript-autoconvert-to-template'
is called whenever a plain string delimiter is typed in the buffer."
:type 'boolean
:group 'typescript)
;;; Public utilities
(defun typescript-convert-to-template ()
"Convert the string at point to a template string."
(interactive)
(save-restriction
(widen)
(save-excursion
(let* ((syntax (syntax-ppss))
(str-terminator (nth 3 syntax))
(string-start (or (and str-terminator (nth 8 syntax))
;; We have to consider the case that we're on the start delimiter of a string.
;; We tentatively take (point) as string-start. If it turns out we're
;; wrong, then typescript--move-to-end-of-plain-string will fail anyway,
;; and we won't use the bogus value.
(progn
(forward-char)
(point)))))
(when (typescript--move-to-end-of-plain-string)
(let ((end-start (or (nth 8 (syntax-ppss)) -1)))
(undo-boundary)
(when (= end-start string-start)
(delete-char 1)
(insert "`")))
(goto-char string-start)
(delete-char 1)
(insert "`"))))))
(defun typescript-autoconvert-to-template ()
"Automatically convert a plain string to a teplate string, if needed.
This function is meant to be automatically invoked when the user
enters plain string delimiters. It checks whether the character
before point is the end of a string. If it is, then it checks
whether the string contains ${...}. If it does, then it converts
the string from a plain string to a template."
(interactive)
(save-restriction
(widen)
(save-excursion
(backward-char)
(when (and (memq (char-after) '(?' ?\"))
(not (eq (char-before) ?\\)))
(let* ((string-start (nth 8 (syntax-ppss))))
(when (and string-start
(save-excursion
(re-search-backward "\\${.*?}" string-start t)))
(typescript-convert-to-template)))))))
;;; KeyMap
(defvar typescript-mode-map
(let ((keymap (make-sparse-keymap)))
(define-key keymap (kbd "C-c '") #'typescript-convert-to-template)
keymap)
"Keymap for `typescript-mode'.")
(defun typescript--post-self-insert-function ()
(when (and (derived-mode-p 'typescript-mode)
typescript-autoconvert-to-template-flag
(or (eq last-command-event ?\')
(eq last-command-event ?\")))
(typescript-autoconvert-to-template)))
;;; Syntax table and parsing
(defvar typescript-mode-syntax-table
(let ((table (make-syntax-table)))
(c-populate-syntax-table table)
(modify-syntax-entry ?$ "_" table)
(modify-syntax-entry ?` "\"" table)
table)
"Syntax table for `typescript-mode'.")
(defvar typescript--quick-match-re nil
"Autogenerated regexp used by `typescript-mode' to match buffer constructs.")
(defvar typescript--quick-match-re-func nil
"Autogenerated regexp used by `typescript-mode' to match constructs and functions.")
(make-variable-buffer-local 'typescript--quick-match-re)
(make-variable-buffer-local 'typescript--quick-match-re-func)
(defvar typescript--cache-end 1
"Last valid buffer position for the `typescript-mode' function cache.")
(make-variable-buffer-local 'typescript--cache-end)
(defvar typescript--last-parse-pos nil
"Latest parse position reached by `typescript--ensure-cache'.")
(make-variable-buffer-local 'typescript--last-parse-pos)
(defvar typescript--state-at-last-parse-pos nil
"Parse state at `typescript--last-parse-pos'.")
(make-variable-buffer-local 'typescript--state-at-last-parse-pos)
(defun typescript--flatten-list (list)
(cl-loop for item in list
nconc (cond ((consp item)
(typescript--flatten-list item))
(item (list item)))))
(defun typescript--maybe-join (prefix separator suffix &rest list)
"Helper function for `typescript--update-quick-match-re'.
If LIST contains any element that is not nil, return its non-nil
elements, separated by SEPARATOR, prefixed by PREFIX, and ended
with SUFFIX as with `concat'. Otherwise, if LIST is empty, return
nil. If any element in LIST is itself a list, flatten that
element."
(setq list (typescript--flatten-list list))
(when list
(concat prefix (mapconcat #'identity list separator) suffix)))
(defun typescript--update-quick-match-re ()
"Internal function used by `typescript-mode' for caching buffer constructs.
This updates `typescript--quick-match-re', based on the current set of
enabled frameworks."
(setq typescript--quick-match-re
(typescript--maybe-join
"^[ \t]*\\(?:" "\\|" "\\)"
;; #define mumble
"#define[ \t]+[a-zA-Z_]"
(when (memq 'exttypescript typescript-enabled-frameworks)
"Ext\\.extend")
(when (memq 'prototype typescript-enabled-frameworks)
"Object\\.extend")
;; var mumble = THING (
(typescript--maybe-join
"\\(?:var[ \t]+\\)?[a-zA-Z_$0-9.]+[ \t]*=[ \t]*\\(?:"
"\\|"
"\\)[ \t]*\("
(when (memq 'prototype typescript-enabled-frameworks)
"Class\\.create")
(when (memq 'exttypescript typescript-enabled-frameworks)
"Ext\\.extend")
(when (memq 'merrillpress typescript-enabled-frameworks)
"[a-zA-Z_$0-9]+\\.extend\\(?:Final\\)?"))
(when (memq 'dojo typescript-enabled-frameworks)
"dojo\\.declare[ \t]*\(")
(when (memq 'mochikit typescript-enabled-frameworks)
"MochiKit\\.Base\\.update[ \t]*\(")
;; mumble.prototypeTHING
(typescript--maybe-join
"[a-zA-Z_$0-9.]+\\.prototype\\(?:" "\\|" "\\)"
(when (memq 'typescript typescript-enabled-frameworks)
'( ;; foo.prototype.bar = function(
"\\.[a-zA-Z_$0-9]+[ \t]*=[ \t]*function[ \t]*\("
;; mumble.prototype = {
"[ \t]*=[ \t]*{")))))
(setq typescript--quick-match-re-func
(concat "function\\|" typescript--quick-match-re)))
(defun typescript--forward-text-property (propname)
"Move over the next value of PROPNAME in the buffer.
If found, return that value and leave point after the character
having that value; otherwise, return nil and leave point at EOB."
(let ((next-value (get-text-property (point) propname)))
(if next-value
(forward-char)
(goto-char (next-single-property-change
(point) propname nil (point-max)))
(unless (eobp)
(setq next-value (get-text-property (point) propname))
(forward-char)))
next-value))
(defun typescript--backward-text-property (propname)
"Move over the previous value of PROPNAME in the buffer.
If found, return that value and leave point just before the
character that has that value, otherwise return nil and leave
point at BOB."
(unless (bobp)
(let ((prev-value (get-text-property (1- (point)) propname)))
(if prev-value
(backward-char)
(goto-char (previous-single-property-change
(point) propname nil (point-min)))
(unless (bobp)
(backward-char)
(setq prev-value (get-text-property (point) propname))))
prev-value)))
(defsubst typescript--forward-pstate ()
(typescript--forward-text-property 'typescript--pstate))
(defsubst typescript--backward-pstate ()
(typescript--backward-text-property 'typescript--pstate))
(defun typescript--pitem-goto-h-end (pitem)
(goto-char (typescript--pitem-h-begin pitem))
(typescript--forward-pstate))
(defun typescript--re-search-forward-inner (regexp &optional bound count)
"Helper function for `typescript--re-search-forward'."
(let ((parse)
str-terminator)
(while (> count 0)
(re-search-forward regexp bound)
(setq parse (syntax-ppss))
(cond ((setq str-terminator (nth 3 parse))
(when (eq str-terminator t)
(setq str-terminator ?/))
(re-search-forward
(concat "\\([^\\]\\|^\\)" (string str-terminator))
(save-excursion (end-of-line) (point)) t))
((nth 7 parse)
(forward-line))
((or (nth 4 parse)
(and (eq (char-before) ?\/) (eq (char-after) ?\*)))
(re-search-forward "\\*/"))
(t
(setq count (1- count))))))
(point))
(defun typescript--re-search-forward (regexp &optional bound noerror count)
"Search forward, ignoring strings and comments.
This function invokes `re-search-forward', but treats the buffer
as if strings and comments have been removed."
(let ((saved-point (point))
(search-fun
(cond ((null count)
(lambda () (typescript--re-search-forward-inner regexp bound 1)))
((< count 0)
(lambda () (typescript--re-search-backward-inner regexp bound (- count))))
((> count 0)
(lambda () (typescript--re-search-forward-inner regexp bound count)))
(t #'ignore))))
(condition-case err
(funcall search-fun)
(search-failed
(goto-char saved-point)
(unless noerror
(error (error-message-string err)))))))
(defun typescript--re-search-backward-inner (regexp &optional bound count)
"Auxiliary function for `typescript--re-search-backward'."
(let ((parse))
(while (> count 0)
(re-search-backward regexp bound)
(when (and (> (point) (point-min))
(save-excursion (backward-char) (looking-at "/[/*]")))
(forward-char))
(setq parse (syntax-ppss))
(cond
;; If we are in a comment or a string, jump back to the start
;; of the comment or string.
((nth 8 parse)
(goto-char (nth 8 parse)))
((and (eq (char-before) ?/) (eq (char-after) ?*))
(re-search-backward "/\\*"))
(t
(setq count (1- count))))))
(point))
(defun typescript--re-search-backward (regexp &optional bound noerror count)
"Search backward, ignoring strings, and comments.
This function invokes `re-search-backward' but treats the buffer
as if strings and comments have been removed.
IMPORTANT NOTE: searching for \"\\n\" with this function to find
line breaks will generally not work, because the final newline of
a one-line comment is considered to be part of the comment and
will be skipped. Take the following code:
let a = 1;
let b = 2; // Foo
let c = 3;
If the point is in the last line, searching back for \"\\n\" will
skip over the line with \"let b\". The newline found will be the
one at the end of the line with \"let a\"."
(let ((saved-point (point))
(search-fun
(cond ((null count)
(lambda () (typescript--re-search-backward-inner regexp bound 1)))
((< count 0)
(lambda () (typescript--re-search-forward-inner regexp bound (- count))))
((> count 0)
(lambda () (typescript--re-search-backward-inner regexp bound count)))
(t #'ignore))))
(condition-case err
(funcall search-fun)
(search-failed
(goto-char saved-point)
(unless noerror
(error (error-message-string err)))))))
(defun typescript--forward-expression ()
"Move forward over a whole typescript expression.
This function doesn't move over expressions continued across
lines."
(cl-loop
do (progn
(forward-comment most-positive-fixnum)
(cl-loop until (or (eolp)
(progn
(forward-comment most-positive-fixnum)
(memq (char-after) '(?\, ?\; ?\] ?\) ?\}))))
do (forward-sexp)))
while (and (eq (char-after) ?\n)
(save-excursion
(forward-char)
(typescript--continued-expression-p)))))
(defun typescript--forward-function-decl ()
"Move forward over a typescript function declaration.
This puts point at the 'function' keyword.
If this is a syntactically-correct non-expression function,
return the name of the function, or t if the name could not be
determined. Otherwise, return nil."
(cl-assert (looking-at "\\_"))
(let ((name t))
(forward-word)
(forward-comment most-positive-fixnum)
(when (looking-at typescript--name-re)
(setq name (match-string-no-properties 0))
(goto-char (match-end 0)))
(forward-comment most-positive-fixnum)
(and (eq (char-after) ?\( )
(ignore-errors (forward-list) t)
(progn (forward-comment most-positive-fixnum)
(and (eq (char-after) ?{)
name)))))
(defun typescript--function-prologue-beginning (&optional pos)
"Return the start of the typescript function prologue containing POS.
A function prologue is everything from start of the definition up
to and including the opening brace. POS defaults to point.
If POS is not in a function prologue, return nil."
(let (prologue-begin)
(save-excursion
(if pos
(goto-char pos)
(setq pos (point)))
(when (save-excursion
(forward-line 0)
(or (looking-at typescript--function-heading-2-re)
(looking-at typescript--function-heading-3-re)))
(setq prologue-begin (match-beginning 1))
(when (<= prologue-begin pos)
(goto-char (match-end 0))))
(skip-syntax-backward "w_")
(and (or (looking-at "\\_")
(typescript--re-search-backward "\\_" nil t))
(save-match-data (goto-char (match-beginning 0))
(typescript--forward-function-decl))
(<= pos (point))
(or prologue-begin (match-beginning 0))))))
(defun typescript--beginning-of-defun-raw ()
"Helper function for `typescript-beginning-of-defun'.
Go to previous defun-beginning and return the parse state for it,
or nil if we went all the way back to bob and don't find
anything."
(typescript--ensure-cache)
(let (pstate)
(while (and (setq pstate (typescript--backward-pstate))
(not (eq 'function (typescript--pitem-type (car pstate))))))
(and (not (bobp)) pstate)))
(defun typescript--pstate-is-toplevel-defun (pstate)
"Helper function for `typescript--beginning-of-defun-nested'.
If PSTATE represents a non-empty top-level defun, return the
top-most pitem. Otherwise, return nil."
(cl-loop for pitem in pstate
with func-depth = 0
with func-pitem
if (eq 'function (typescript--pitem-type pitem))
do (cl-incf func-depth)
and do (setq func-pitem pitem)
finally return (if (eq func-depth 1) func-pitem)))
(defun typescript--beginning-of-defun-nested ()
"Helper function for `typescript--beginning-of-defun'.
Return the pitem of the function we went to the beginning of."
(or
;; Look for the smallest function that encloses point...
(cl-loop for pitem in (typescript--parse-state-at-point)
if (and (eq 'function (typescript--pitem-type pitem))
(typescript--inside-pitem-p pitem))
do (goto-char (typescript--pitem-h-begin pitem))
and return pitem)
;; ...and if that isn't found, look for the previous top-level
;; defun
(cl-loop for pstate = (typescript--backward-pstate)
while pstate
if (typescript--pstate-is-toplevel-defun pstate)
do (goto-char (typescript--pitem-h-begin it))
and return it)))
(defun typescript--beginning-of-defun-flat ()
"Helper function for `typescript-beginning-of-defun'."
(let ((pstate (typescript--beginning-of-defun-raw)))
(when pstate
(goto-char (typescript--pitem-h-begin (car pstate))))))
(defun typescript-beginning-of-defun (&optional arg)
"Value of `beginning-of-defun-function' for `typescript-mode'."
(setq arg (or arg 1))
(while (and (not (eobp)) (< arg 0))
(cl-incf arg)
(when (and (not typescript-flat-functions)
(or (eq (typescript-syntactic-context) 'function)
(typescript--function-prologue-beginning)))
(typescript-end-of-defun))
(if (typescript--re-search-forward
"\\_" nil t)
(goto-char (typescript--function-prologue-beginning))
(goto-char (point-max))))
(while (> arg 0)
(cl-decf arg)
;; If we're just past the end of a function, the user probably wants
;; to go to the beginning of *that* function
(when (eq (char-before) ?})
(backward-char))
(let ((prologue-begin (typescript--function-prologue-beginning)))
(cond ((and prologue-begin (< prologue-begin (point)))
(goto-char prologue-begin))
(typescript-flat-functions
(typescript--beginning-of-defun-flat))
(t
(typescript--beginning-of-defun-nested))))))
(defun typescript--flush-caches (&optional beg ignored)
"Flush the `typescript-mode' syntax cache after position BEG.
BEG defaults to `point-min', meaning to flush the entire cache."
(interactive)
(setq beg (or beg (save-restriction (widen) (point-min))))
(setq typescript--cache-end (min typescript--cache-end beg)))
(defmacro typescript--debug (&rest arguments)
;; `(message ,@arguments)
)
(defun typescript--ensure-cache--pop-if-ended (open-items paren-depth)
(let ((top-item (car open-items)))
(when (<= paren-depth (typescript--pitem-paren-depth top-item))
(cl-assert (not (get-text-property (1- (point)) 'typescript-pend)))
(put-text-property (1- (point)) (point) 'typescript--pend top-item)
(setf (typescript--pitem-b-end top-item) (point))
(setq open-items
;; open-items must contain at least two items for this to
;; work, but because we push a dummy item to start with,
;; that assumption holds.
(cons (typescript--pitem-add-child (cl-second open-items) top-item)
(cddr open-items)))))
open-items)
(defmacro typescript--ensure-cache--update-parse ()
"Helper function for `typescript--ensure-cache'.
Update parsing information up to point, referring to parse,
prev-parse-point, goal-point, and open-items bound lexically in
the body of `typescript--ensure-cache'."
`(progn
(setq goal-point (point))
(goto-char prev-parse-point)
(while (progn
(setq open-items (typescript--ensure-cache--pop-if-ended
open-items (car parse)))
;; Make sure parse-partial-sexp doesn't stop because we *entered*
;; the given depth -- i.e., make sure we're deeper than the target
;; depth.
(cl-assert (> (nth 0 parse)
(typescript--pitem-paren-depth (car open-items))))
(setq parse (parse-partial-sexp
prev-parse-point goal-point
(typescript--pitem-paren-depth (car open-items))
nil parse))
;; (let ((overlay (make-overlay prev-parse-point (point))))
;; (overlay-put overlay 'face '(:background "red"))
;; (unwind-protect
;; (progn
;; (typescript--debug "parsed: %S" parse)
;; (sit-for 1))
;; (delete-overlay overlay)))
(setq prev-parse-point (point))
(< (point) goal-point)))
(setq open-items (typescript--ensure-cache--pop-if-ended
open-items (car parse)))))
(defun typescript--show-cache-at-point ()
(interactive)
(require 'pp)
(let ((prop (get-text-property (point) 'typescript--pstate)))
(with-output-to-temp-buffer "*Help*"
(pp prop))))
(defun typescript--split-name (string)
"Split a typescript name into its dot-separated parts.
This also removes any prototype parts from the split name
\(unless the name is just \"prototype\" to start with)."
(let ((name (save-match-data
(split-string string "\\." t))))
(unless (and (= (length name) 1)
(equal (car name) "prototype"))
(setq name (remove "prototype" name)))))
(defvar typescript--guess-function-name-start nil)
(defun typescript--guess-function-name (position)
"Guess the name of the typescript function at POSITION.
POSITION should be just after the end of the word \"function\".
Return the name of the function, or nil if the name could not be
guessed.
This function clobbers match data. If we find the preamble
begins earlier than expected while guessing the function name,
set `typescript--guess-function-name-start' to that position; otherwise,
set that variable to nil."
(setq typescript--guess-function-name-start nil)
(save-excursion
(goto-char position)
(forward-line 0)
(cond
((looking-at typescript--function-heading-3-re)
(and (eq (match-end 0) position)
(setq typescript--guess-function-name-start (match-beginning 1))
(match-string-no-properties 1)))
((looking-at typescript--function-heading-2-re)
(and (eq (match-end 0) position)
(setq typescript--guess-function-name-start (match-beginning 1))
(match-string-no-properties 1))))))
(defun typescript--clear-stale-cache ()
;; Clear any endings that occur after point
(let (end-prop)
(save-excursion
(while (setq end-prop (typescript--forward-text-property
'typescript--pend))
(setf (typescript--pitem-b-end end-prop) nil))))
;; Remove any cache properties after this point
(remove-text-properties (point) (point-max)
'(typescript--pstate t typescript--pend t)))
(defun typescript--ensure-cache (&optional limit)
"Ensures brace cache is valid up to the character before LIMIT.
LIMIT defaults to point."
(setq limit (or limit (point)))
(when (< typescript--cache-end limit)
(c-save-buffer-state
(open-items
orig-match-start
orig-match-end
orig-depth
parse
prev-parse-point
name
case-fold-search
filtered-class-styles
new-item
goal-point
end-prop)
;; Figure out which class styles we need to look for
(setq filtered-class-styles
(cl-loop for style in typescript--class-styles
if (memq (plist-get style :framework)
typescript-enabled-frameworks)
collect style))
(save-excursion
(save-restriction
(widen)
;; Find last known good position
(goto-char typescript--cache-end)
(unless (bobp)
(setq open-items (get-text-property
(1- (point)) 'typescript--pstate))
(unless open-items
(goto-char (previous-single-property-change
(point) 'typescript--pstate nil (point-min)))
(unless (bobp)
(setq open-items (get-text-property (1- (point))
'typescript--pstate))
(cl-assert open-items))))
(unless open-items
;; Make a placeholder for the top-level definition
(setq open-items (list typescript--initial-pitem)))
(setq parse (syntax-ppss))
(setq prev-parse-point (point))
(typescript--clear-stale-cache)
(narrow-to-region (point-min) limit)
(cl-loop while (re-search-forward typescript--quick-match-re-func nil t)
for orig-match-start = (goto-char (match-beginning 0))
for orig-match-end = (match-end 0)
do (typescript--ensure-cache--update-parse)
for orig-depth = (nth 0 parse)
;; Each of these conditions should return non-nil if
;; we should add a new item and leave point at the end
;; of the new item's header (h-end in the
;; typescript--pitem diagram). This point is the one
;; after the last character we need to unambiguously
;; detect this construct. If one of these evaluates to
;; nil, the location of the point is ignored.
if (cond
;; In comment or string
((nth 8 parse) nil)
;; Regular function declaration
((and (looking-at "\\_")
(setq name (typescript--forward-function-decl)))
(when (eq name t)
(setq name (typescript--guess-function-name orig-match-end))
(if name
(when typescript--guess-function-name-start
(setq orig-match-start
typescript--guess-function-name-start))
(setq name t)))
(cl-assert (eq (char-after) ?{))
(forward-char)
(make-typescript--pitem
:paren-depth orig-depth
:h-begin orig-match-start
:type 'function
:name (if (eq name t)
name
(typescript--split-name name))))
;; "Prototype function" declaration
((looking-at typescript--plain-method-re)
(goto-char (match-beginning 3))
(when (save-match-data
(typescript--forward-function-decl))
(forward-char)
(make-typescript--pitem
:paren-depth orig-depth
:h-begin orig-match-start
:type 'function
:name (nconc (typescript--split-name
(match-string-no-properties 1))
(list (match-string-no-properties 2))))))
;; Class definition
((cl-loop with syntactic-context =
(typescript--syntactic-context-from-pstate open-items)
for class-style in filtered-class-styles
if (and (memq syntactic-context
(plist-get class-style :contexts))
(looking-at (plist-get class-style
:class-decl)))
do (goto-char (match-end 0))
and return
(make-typescript--pitem
:paren-depth orig-depth
:h-begin orig-match-start
:type class-style
:name (typescript--split-name
(match-string-no-properties 1))))))
do (typescript--ensure-cache--update-parse)
and do (push it open-items)
and do (put-text-property
(1- (point)) (point) 'typescript--pstate open-items)
else do (goto-char orig-match-end))
(goto-char limit)
(typescript--ensure-cache--update-parse)
(setq typescript--cache-end limit)
(setq typescript--last-parse-pos limit)
(setq typescript--state-at-last-parse-pos open-items))))))
(defun typescript--end-of-defun-flat ()
"Helper function for `typescript-end-of-defun'."
(cl-loop while (typescript--re-search-forward "}" nil t)
do (typescript--ensure-cache)
if (get-text-property (1- (point)) 'typescript--pend)
if (eq 'function (typescript--pitem-type it))
return t
finally do (goto-char (point-max))))
(defun typescript--end-of-defun-nested ()
"Helper function for `typescript-end-of-defun'."
(let* (pitem
(this-end (save-excursion
(and (setq pitem (typescript--beginning-of-defun-nested))
(typescript--pitem-goto-h-end pitem)
(progn (backward-char)
(forward-list)
(point)))))
found)
(if (and this-end (< (point) this-end))
;; We're already inside a function; just go to its end.
(goto-char this-end)
;; Otherwise, go to the end of the next function...
(while (and (typescript--re-search-forward "\\_" nil t)
(not (setq found (progn
(goto-char (match-beginning 0))
(typescript--forward-function-decl))))))
(if found (forward-list)
;; ... or eob.
(goto-char (point-max))))))
(defun typescript-end-of-defun (&optional arg)
"Value of `end-of-defun-function' for `typescript-mode'."
(setq arg (or arg 1))
(while (and (not (bobp)) (< arg 0))
(cl-incf arg)
(typescript-beginning-of-defun)
(typescript-beginning-of-defun)
(unless (bobp)
(typescript-end-of-defun)))
(while (> arg 0)
(cl-decf arg)
;; look for function backward. if we're inside it, go to that
;; function's end. otherwise, search for the next function's end and
;; go there
(if typescript-flat-functions
(typescript--end-of-defun-flat)
;; if we're doing nested functions, see whether we're in the
;; prologue. If we are, go to the end of the function; otherwise,
;; call typescript--end-of-defun-nested to do the real work
(let ((prologue-begin (typescript--function-prologue-beginning)))
(cond ((and prologue-begin (<= prologue-begin (point)))
(goto-char prologue-begin)
(re-search-forward "\\_ void
(and "(")
;; closing of a function type argument.
;; here, the type of `f'.
;; (f: (x: number) => foo): void => { }
(and ")" (? (* whitespace) "=>" (* whitespace)))
(and ","
(* whitespace)
(regexp "[a-zA-Z_$]\\(?:\\s_\\|\\sw\\)*")
;; optional ? to mark the
;; argument optional
(? "?")
(group (or ":" ")")))))
nil t))
;; In case the skipped type was the end of a
;; function type argument, the next token is the
;; return type of the inner function, so we need to
;; match but not fontify the next "name" (which
;; really is the type).
(if (string-match-p "=>" (match-string 0))
(setq perform-match t)
(goto-char (match-beginning 0))
(setq perform-match nil))))))))
;; conditions to handle
(scan-error nil)
(end-of-buffer nil))
nil)
(defun typescript--in-documentation-comment-p ()
"Reports whether point is inside a documentation comment."
(let ((parse (syntax-ppss)))
(and
(nth 4 parse) ;; Inside a comment ...
(save-match-data
(save-excursion
(goto-char (nth 8 parse))
(looking-at "/\\*\\*")))))) ;; ... which starts with /**
(defun typescript--documentation-font-lock-helper (re limit)
"This is a helper macro that determines whether jsdoc highlighting is to be applied,
and searches for the next token to be highlighted."
(cl-loop while (re-search-forward re limit t)
if (typescript--in-documentation-comment-p)
return (point)))
(defun typescript--jsdoc-param-matcher (limit)
"Font-lock mode matcher that finds jsdoc parameter tags in documentation."
(typescript--documentation-font-lock-helper typescript-jsdoc-param-tag-regexp limit))
(defun typescript--jsdoc-typed-tag-matcher (limit)
"Font-lock mode matcher that finds jsdoc typed tags in documentation."
(typescript--documentation-font-lock-helper typescript-jsdoc-typed-tag-regexp limit))
(defun typescript--jsdoc-arg-tag-matcher (limit)
"Font-lock mode matcher that finds jsdoc tags that take one argument in documentation."
(typescript--documentation-font-lock-helper typescript-jsdoc-arg-tag-regexp limit))
(defun typescript--jsdoc-empty-tag-matcher (limit)
"Font-lock mode matcher that finds jsdoc tags without argument in documentation."
(typescript--documentation-font-lock-helper typescript-jsdoc-empty-tag-regexp limit))
(defun typescript--typedoc-link-matcher (limit)
"Font-lock mode matcher that finds typedoc links in documentation."
(typescript--documentation-font-lock-helper typescript-typedoc-link-tag-regexp limit))
(defun typescript--typedoc-literal-markup-matcher (limit)
"Font-lock mode matcher that finds typedoc literal markup in documentation."
(typescript--documentation-font-lock-helper typescript-typedoc-literal-markup-regexp limit))
(defun typescript--tslint-flag-matcher (limit)
"Font-lock mode matcher that finds tslint flags in comments."
(cl-loop while (re-search-forward typescript-tslint-flag-regexp limit t)
if (nth 4 (syntax-ppss (match-beginning 1)))
return (point)))
(defconst typescript--font-lock-keywords-3
`(
,@typescript--font-lock-keywords-2
;; Remove the fontification of keywords and built-ins when they
;; are keys in an interface, object or class.
(,(rx "{")
(,(concat "\\(" typescript--keyword-re "\\):")
(save-excursion (ignore-errors (up-list)) (point))
nil
(1 'default t t)))
(typescript--jsdoc-param-matcher (1 'typescript-jsdoc-tag t t)
(2 'typescript-jsdoc-type t t)
(3 'typescript-jsdoc-value t t))
(typescript--jsdoc-typed-tag-matcher (1 'typescript-jsdoc-tag t t)
(2 'typescript-jsdoc-type t t))
(typescript--jsdoc-arg-tag-matcher (1 'typescript-jsdoc-tag t t)
(2 'typescript-jsdoc-value t t))
(typescript--jsdoc-empty-tag-matcher (1 'typescript-jsdoc-tag t t))
(typescript--typedoc-link-matcher (0 'typescript-jsdoc-value t))
(typescript--typedoc-literal-markup-matcher
(0 'typescript-jsdoc-value t))
(typescript--tslint-flag-matcher
(1 'font-lock-preprocessor-face t))
("\\.\\(prototype\\)\\_>"
(1 'font-lock-constant-face))
(,(rx symbol-start "class" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
(1 'font-lock-type-face))
(,(rx symbol-start "extends" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
(1 'font-lock-type-face))
(,(rx symbol-start "implements" (+ space))
(,(rx symbol-start (+ (syntax word))) nil nil (0 'font-lock-type-face)))
(,(rx symbol-start "interface" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
(1 'font-lock-type-face))
(,(rx symbol-start "type" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
(1 'font-lock-type-face))
(,(rx symbol-start "enum" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
(1 'font-lock-type-face))
;; Highlights class being declared, in parts
(typescript--class-decl-matcher
,(concat "\\(" typescript--name-re "\\)\\(?:\\.\\|.*$\\)")
(goto-char (match-beginning 1))
nil
(1 'font-lock-type-face))
;; Highlights parent class, in parts, if available
(typescript--class-decl-matcher
,(concat "\\(" typescript--name-re "\\)\\(?:\\.\\|.*$\\)")
(if (match-beginning 2)
(progn
(setq typescript--tmp-location (match-end 2))
(goto-char typescript--tmp-location)
(insert "=")
(goto-char (match-beginning 2)))
(setq typescript--tmp-location nil)
(goto-char (point-at-eol)))
(when typescript--tmp-location
(save-excursion
(goto-char typescript--tmp-location)
(delete-char 1)))
(1 'font-lock-type-face))
;; Highlights parent class
(typescript--class-decl-matcher
(2 'font-lock-type-face nil t))
;; Dojo needs its own matcher to override the string highlighting
(,(typescript--make-framework-matcher
'dojo
"^\\s-*dojo\\.declare\\s-*(\""
"\\(" typescript--dotted-name-re "\\)"
"\\(?:\"\\s-*,\\s-*\\(" typescript--dotted-name-re "\\)\\)?")
(1 'font-lock-type-face t)
(2 'font-lock-type-face nil t))
;; Match Dojo base classes. Of course Mojo has to be different
;; from everything else under the sun...
(,(typescript--make-framework-matcher
'dojo
"^\\s-*dojo\\.declare\\s-*(\""
"\\(" typescript--dotted-name-re "\\)\"\\s-*,\\s-*\\[")
,(concat "[[,]\\s-*\\(" typescript--dotted-name-re "\\)\\s-*"
"\\(?:\\].*$\\)?")
(backward-char)
(end-of-line)
(1 'font-lock-type-face))
;; continued Dojo base-class list
(,(typescript--make-framework-matcher
'dojo
"^\\s-*" typescript--dotted-name-re "\\s-*[],]")
,(concat "\\(" typescript--dotted-name-re "\\)"
"\\s-*\\(?:\\].*$\\)?")
(if (save-excursion (backward-char)
(typescript--inside-dojo-class-list-p))
(forward-symbol -1)
(end-of-line))
(end-of-line)
(1 'font-lock-type-face))
;; variable declarations
,(list
(concat "\\_<\\(const\\|var\\|let\\)\\_>\\|" typescript--basic-type-re)
(list #'typescript--variable-decl-matcher nil nil nil))
;; class instantiation
(,(concat "\\_\\s-+\\(" typescript--dotted-name-re "\\)")
(1 'font-lock-type-face))
;; instanceof
(,(concat "\\_\\s-+\\(" typescript--dotted-name-re "\\)")
(1 'font-lock-type-face))
;; formal parameters in "function" function call
;; function helloWorld(a: number, b: Promise): void { }
,(list
(concat
"\\_\\(\\s-+" typescript--name-re "\\)?\\s-*\\(<.*>\\)?\\s-*(\\s-*"
"\\(?:$\\|" typescript--name-start-re "\\)")
`(typescript--function-argument-matcher
(prog1 (save-excursion (ignore-errors (up-list)) (point))
(backward-char))
nil
nil))
;; formal parameters in arrow function
;; const helloWorld = (a: number, b: Promise): void => { }
,(list
(rx (group "=>") (* whitespace) (? eol) (* whitespace) "{")
'(1 font-lock-keyword-face)
`(typescript--function-argument-matcher
(prog1 (progn
(backward-char)
(typescript--backward-to-parameter-list)
(point))
(backward-sexp))
(re-search-forward "{" nil t)
nil))
;; formal parameters in method definitions
;; class Foo { helloWorld(a: number, b: Promise): void { } }
,(list
typescript--function-call-re
`(typescript--function-argument-matcher
(let ((point-orig (point))
(is-method-def
(ignore-errors
(up-list)
(and
(or
;; After the "argument list" is a bracket, this is
;; either a special form (if, while...) or a method
;; declaration.
(looking-at-p (rx (* (or whitespace ?\n)) "{"))
;; After the "argument list" is a colon, this is
;; either a method declaration with a return type
;; annotation or ternary form. We need to discard
;; the ternary form case.
(and
(looking-at-p (rx (* (or whitespace ?\n)) ":"))
(save-excursion
(backward-sexp 2)
(skip-syntax-backward " >")
(not (eq (char-before) ??)))))
;; HACK: here we check the fontification of
;; the "function name". Because the keywords
;; are fontified before this check runs, a
;; keyword would already have been fontified
;; and therefore we can conclude it is not a
;; function/method definition.
(save-excursion
(backward-sexp)
(backward-word)
(not (memq
'font-lock-keyword-face
(face-at-point nil t))))))))
(if is-method-def
(prog1 (point) (goto-char point-orig))
(point)))
nil
nil)))
"Level three font lock for `typescript-mode'.")
(defun typescript--flyspell-mode-predicate ()
"A custom predicate to help `flyspell-prog-mode' determine whether a word should be checked."
;; We depend on fontification for our results. font-lock-ensure is defined on
;; Emacs 25 and over. Earlier versions use font-lock-fontify-buffer.
(if (fboundp 'font-lock-ensure)
(font-lock-ensure)
(font-lock-fontify-buffer))
(and
;; Check with the default method that flyspell provides.
(flyspell-generic-progmode-verify)
;;
;; And eliminate cases specific to our mode we don't want to have
;; spell-checked.
;;
;; Don't check the module names in import statements.
(save-excursion
(not (let* ((parse (syntax-ppss (1- (point))))
(string-start-pos (and (nth 3 parse)
(nth 8 parse))))
(and string-start-pos
(save-match-data
;; Move to back to the start of the string, then past any ws
;; and then past any non-ws to see if we have "from" or "import".
(goto-char string-start-pos)
(typescript--backward-syntactic-ws)
(skip-syntax-backward "^-" (point-at-bol))
(looking-at "from\\|import\\s-"))))))))
(defun typescript--inside-pitem-p (pitem)
"Return whether point is inside the given pitem's header or body."
(typescript--ensure-cache)
(cl-assert (typescript--pitem-h-begin pitem))
(cl-assert (typescript--pitem-paren-depth pitem))
(and (> (point) (typescript--pitem-h-begin pitem))
(or (null (typescript--pitem-b-end pitem))
(> (typescript--pitem-b-end pitem) (point)))))
(defun typescript--parse-state-at-point ()
"Parse the typescript program state at point.
Return a list of `typescript--pitem' instances that apply to point, most
specific first. In the worst case, the current toplevel instance
will be returned."
(save-excursion
(save-restriction
(widen)
(typescript--ensure-cache)
(let* ((bound (if (eobp) (point) (1+ (point))))
(pstate (or (save-excursion
(typescript--backward-pstate))
(list typescript--initial-pitem))))
;; Loop until we either hit a pitem at BOB or pitem ends after
;; point (or at point if we're at eob)
(cl-loop for pitem = (car pstate)
until (or (eq (typescript--pitem-type pitem)
'toplevel)
(typescript--inside-pitem-p pitem))
do (pop pstate))
pstate))))
(defun typescript--syntactic-context-from-pstate (pstate)
"Return the typescript syntactic context corresponding to PSTATE."
(let ((type (typescript--pitem-type (car pstate))))
(cond ((memq type '(function macro))
type)
((consp type)
'class)
(t 'toplevel))))
(defun typescript-syntactic-context ()
"Return the typescript syntactic context at point.
When called interactively, also display a message with that
context."
(interactive)
(let* ((syntactic-context (typescript--syntactic-context-from-pstate
(typescript--parse-state-at-point))))
(when (called-interactively-p 'interactive)
(message "Syntactic context: %s" syntactic-context))
syntactic-context))
(defun typescript--class-decl-matcher (limit)
"Font lock function used by `typescript-mode'.
This performs fontification according to `typescript--class-styles'."
(cl-loop initially (typescript--ensure-cache limit)
while (re-search-forward typescript--quick-match-re limit t)
for orig-end = (match-end 0)
do (goto-char (match-beginning 0))
if (cl-loop for style in typescript--class-styles
for decl-re = (plist-get style :class-decl)
if (and (memq (plist-get style :framework)
typescript-enabled-frameworks)
(memq (typescript-syntactic-context)
(plist-get style :contexts))
decl-re
(looking-at decl-re))
do (goto-char (match-end 0))
and return t)
return t
else do (goto-char orig-end)))
(defun typescript--match-subst-in-quotes (limit)
"Match dollar substitutions inside backticks."
(catch 'done
(while (re-search-forward
;; `rx' is cool, mkay.
(rx (or line-start (not (any "\\")))
(group "${")
(group (+? nonl))
(group "}"))
limit t)
(let ((string-delim (nth 3 (syntax-ppss))))
(when (and string-delim (= string-delim 96))
(throw 'done (point)))))))
(defconst typescript--font-lock-keywords-4
`(
;; highlights that override previous levels
;;
;; special highlight for `this' keyword
("\\(this\\)\\."
(1 'typescript-this-face))
(,typescript--access-modifier-re (1 'typescript-access-modifier-face))
(,typescript--basic-type-re (1 'typescript-primitive-face))
;; generics support
,(list
(concat typescript--name-re "\\s-*" "<\\s-*" typescript--name-start-re)
(list (concat "\\(" typescript--name-re "\\)\\(\\s-*>[^<]*\\)?")
'(backward-char)
'(end-of-line)
'(1 font-lock-type-face)))
;; type-highlighting in variable/parameter declarations
;; supports a small variety of common declarations:
;; - let a: SomeType;
;; - private b: SomeType;
;; - private someFunc(var: SomeType) {
;; - private array: SomeType[]
;; - private generic: SomeType
;; - private genericArray: SomeType[]
;; - function testFunc(): SomeType<> {
;; - function testFunc(a): a is SomeType<> {
;; - () => SomeType
;; TODO: namespaced classes!
,(list
(concat "\\(?::\\|=>\\)\\s-\\(?:\\s-*\\(" typescript--name-re "\\)\\s-*\\(is\\)\\s-*\\)?" "\\(" typescript--type-name-re "\\)\\(<" typescript--type-name-re ">\\)?\\(\\[\\]\\)?\\([,;]\\)?\\s-*{?")
'(1 'font-lock-variable-name-face nil t)
'(2 'font-lock-keyword-face nil t)
'(3 'font-lock-type-face))
;; type-casts
,(list
(concat "<\\(" typescript--type-name-re "\\)>")
'(1 'font-lock-type-face))
;; highlights that append to previous levels
;;
,@typescript--font-lock-keywords-3
(,typescript--decorator-re (1 'font-lock-function-call-face))
(,typescript--function-call-re (1 (typescript--function-face)))
(,(concat "\\(?:\\.\\s-*\\)" typescript--function-call-re)
(1 'font-lock-function-call-face t))
(,typescript--builtin-re (1 'font-lock-type-face))
;; arrow function
("\\(=>\\)"
(1 'font-lock-keyword-face))
(typescript--match-subst-in-quotes
(1 'font-lock-keyword-face t)
(2 'default t)
(3 'font-lock-keyword-face t)))
"Level four font lock for `typescript-mode'.")
(defun typescript--function-face ()
"Return the face to use depending if it's a definition or a call.
Point is assumed to be right after the open paren."
(save-excursion
(forward-char -1)
(if (condition-case nil
(progn
(forward-sexp 1)
(forward-comment (point-max))
(memq (char-after) '(?: ?\{)))
(scan-error nil))
;; Looks like a declaration/definition.
'font-lock-function-name-face
;; Probably just a call.
'font-lock-function-call-face)))
(defconst typescript--font-lock-keywords
'(typescript--font-lock-keywords-4 typescript--font-lock-keywords-1
typescript--font-lock-keywords-2
typescript--font-lock-keywords-3
typescript--font-lock-keywords-4)
"Font lock keywords for `typescript-mode'. See `font-lock-keywords'.")
;;; Propertize
;;
;; The propertize code was adapted from:
;; https://github.com/emacs-mirror/emacs/blob/489d6466372f488adc53897435fff290394b62f7/lisp/progmodes/js.el
;;
(defconst typescript--syntax-propertize-regexp-regexp
(rx
;; Start of regexp.
"/"
(0+ (or
;; Match characters outside of a character class.
(not (any ?\[ ?/ ?\\))
;; Match backslash quoted characters.
(and "\\" not-newline)
;; Match character class.
(and
"["
(0+ (or
(not (any ?\] ?\\))
(and "\\" not-newline)))
"]")))
(group (zero-or-one "/")))
"Regular expression matching a JavaScript regexp literal.")
(defun typescript-syntax-propertize-regexp (end)
(let ((ppss (syntax-ppss)))
(when (eq (nth 3 ppss) ?/)
;; A /.../ regexp.
(goto-char (nth 8 ppss))
(when (looking-at typescript--syntax-propertize-regexp-regexp)
;; Don't touch text after END.
(when (> end (match-end 1))
(setq end (match-end 1)))
(put-text-property (match-beginning 1) end
'syntax-table (string-to-syntax "\"/"))
(goto-char end)))))
(defun typescript-syntax-propertize (start end)
;; JavaScript allows immediate regular expression objects, written /.../.
(funcall
(syntax-propertize-rules
;; Distinguish /-division from /-regexp chars (and from /-comment-starter).
;; FIXME: Allow regexps after infix ops like + ...
;; https://developer.mozilla.org/en/JavaScript/Reference/Operators
;; We can probably just add +, -, <, >, %, ^, ~, ?, : at which
;; point I think only * and / would be missing which could also be added,
;; but need care to avoid affecting the // and */ comment markers.
("\\(?:^\\|[=([{,:;|&!]\\|\\_\\)\\(?:[ \t]\\)*\\(/\\)[^/*]"
(1 (ignore
(forward-char -1)
(when (or (not (memq (char-after (match-beginning 0)) '(?\s ?\t)))
;; If the / is at the beginning of line, we have to check
;; the end of the previous text.
(save-excursion
(goto-char (match-beginning 0))
(forward-comment (- (point)))
(memq (char-before)
(eval-when-compile (append "=({[,:;" '(nil))))))
(put-text-property (match-beginning 1) (match-end 1)
'syntax-table (string-to-syntax "\"/"))
(typescript-syntax-propertize-regexp end)))))
;; Hash-bang at beginning of buffer.
("\\`\\(#\\)!" (1 "< b")))
start end))
;;; Indentation
(defconst typescript--possibly-braceless-keyword-re
(typescript--regexp-opt-symbol
'("catch" "do" "else" "finally" "for" "if" "try" "while" "with"))
"Regexp matching keywords optionally followed by an opening brace.")
(defconst typescript--indent-keyword-re
(typescript--regexp-opt-symbol '("in" "instanceof"))
"Regexp matching keywords that affect indentation of continued expressions.")
(defconst typescript--indent-operator-re
(concat "[-+*/%<>=&^|?:.]\\([^-+*/]\\|$\\)\\|" typescript--indent-keyword-re)
"Regexp matching operators that affect indentation of continued expressions.")
;;
;; We purposely do not allow the plus symbol as a prefix here, as this
;; regex is used to check number literal in type annotations, and TS
;; does not allow to use a plus symbol to prefix numbers there: you
;; can use 1, but not +1 in a type annotation.
;;
;; This is meant to match NaN, floats, decimals, the two infinities
;; and numbers recorded in binary, octal and hex.
;;
;; This regular expression was derived from:
;; https://stackoverflow.com/a/30987109/
;;
(defconst typescript--number-literal-re
"\\(?:NaN\\|-?\\(?:0[Bb][01]+\\|0[Oo][0-7]+\\|0[Xx][0-9a-fA-F]+\\|Infinity\\|\\(?:[[:digit:]]*\\.[[:digit:]]+\\|[[:digit:]]+\\)\\(?:[Ee][+-]?[[:digit:]]+\\)?\\)\\)"
"Regexp that matches number literals.")
(defconst typescript--reserved-start-keywords
'("const" "export" "function" "let" "var")
"These keywords cannot be variable or type names and start a new sentence.
Note that the \"import\" keyword can be a type import since TS2.9, so it might
not start a sentence!")
(defconst typescript--reserved-start-keywords-re
(typescript--regexp-opt-symbol '("const" "export" "function" "let" "var"))
"A regular expression matching `typescript--reserved-start-keywords'.")
(defconst typescript--type-vs-ternary-re
(concat "[?]\\|" (typescript--regexp-opt-symbol
(append typescript--reserved-start-keywords
'("as" "class" "interface" "private" "public" "readonly"))))
"Keywords/Symbols that help tell apart colon for types vs ternary operators.")
(defun typescript--search-backward-matching-angle-bracket-inner (depth)
"Auxiliary function for `typescript--search-backward-matching-angle-bracket'.
DEPTH indicates how nested we think we are: it increases when we cross closing
brackets, and decreases when we cross opening brackets."
;; We look backwards for a "<" that would correspond to the ">" we started
;; from. However, there is no guarantee that it exists, since our ">" could
;; be a greater-than operation. Some symbols will make it clear that we are
;; *not* in a type annotation, so we can return nil. Otherwise, we keep
;; looking for the matching one.
(or (<= depth 0)
(and
;; If we cross over a reserved start keyword, we abandon hope of finding
;; a matching angle bracket. This prevents extreme recursion depths.
(typescript--re-search-backward (concat "[<>]\\|" typescript--reserved-start-keywords-re) nil t)
(cl-case (char-after)
(?< (typescript--search-backward-matching-angle-bracket-inner (- depth 1)))
(?> (typescript--search-backward-matching-angle-bracket-inner (+ depth 1)))))))
(defun typescript--search-backward-matching-angle-bracket ()
"Search for matching \"<\" preceding a starting \">\".
DEPTH indicates how nested we think we are. Assumes the starting position is
right before the closing \">\". Returns nil when a match was not found,
otherwise returns t and the current position is right before the matching
\"<\"."
(typescript--search-backward-matching-angle-bracket-inner 1))
(defun typescript--re-search-backward-ignoring-angle-brackets ()
"Search backwards, jumping over text within angle brackets.
Searches specifically for any of \"=\", \"}\", and \"type\"."
(and
(typescript--re-search-backward "[>=}]\\|\\_" nil t)
(or (not (looking-at ">"))
(and
(typescript--search-backward-matching-angle-bracket)
(typescript--re-search-backward-ignoring-angle-brackets)))))
(defun typescript--looking-at-operator-p ()
"Return non-nil if point is on a typescript operator, other than a comma."
(save-match-data
(and (looking-at typescript--indent-operator-re)
(or (not (looking-at ":"))
(save-excursion
(backward-sexp)
(and
(typescript--re-search-backward "[?:{]\\|\\_" nil t)
(looking-at "?"))))
;; Do not identify forward slashes appearing in a "list" as
;; an operator. The lists are: arrays, or lists of
;; arguments. In this context, they must be part of regular
;; expressions, and not math operators.
(not (and (looking-at "/")
(save-excursion
(typescript--backward-syntactic-ws)
(memq (char-before) '(?, ?\[ ?\()))))
;; Do not identify methods, or fields, that are named "in" or
;; "instanceof" as being operator keywords.
(not (and
(looking-at typescript--indent-keyword-re)
(save-excursion
(typescript--backward-syntactic-ws)
(memq (char-before) '(?, ?{ ?} ?\;)))))
;; Do not identify the symbol > if it is likely part of a type argument
;; T, but identify it if it is likely a greater-than symbol. This is
;; a hard problem in the absence of semicolons, see:
;; https://github.com/ananthakumaran/typescript.el/issues/81
(not (and
(looking-at ">")
(save-excursion
(and
(typescript--search-backward-matching-angle-bracket)
;; If we made it here, we found a candidate matching opening
;; angle bracket. We still need to guess whether it actually
;; is one, and not a spurious less-than operator!
;; Look backwards for the first of:
;; - one of the symbols: = :
;; - or a TypeScript keyword
;; Depending on what comes first, we can make an educated
;; guess on the nature of our ">" of interest.
(typescript--re-search-backward (concat "[=:]\\|" typescript--keyword-re) nil t)
(or
;; If the previous keyword is "as", definitely a type.
(looking-at "\\_")
;; Same goes for type imports.
(looking-at "\\_")
;; A colon could be either a type symbol, or a ternary
;; operator, try to guess which.
(and (looking-at ":")
(typescript--re-search-backward typescript--type-vs-ternary-re nil t)
(not (looking-at "?")))
;; This final check lets us distinguish between a
;; 2-argument type "t < a , b > ..." and a use of the ","
;; operator between two comparisons "t < a , b > ...".
;; Looking back a little more lets us guess.
(and (looking-at "=")
(typescript--re-search-backward-ignoring-angle-brackets)
(looking-at "\\_")))))))
(not (and
(looking-at "*")
;; Generator method (possibly using computed property).
(looking-at (concat "\\* *\\(?:\\[\\|" typescript--name-re
" *(\\)"))
(save-excursion
(typescript--backward-syntactic-ws)
;; We might misindent some expressions that would
;; return NaN anyway. Shouldn't be a problem.
(memq (char-before) '(?, ?} ?{ ?\;))))))))
(defun typescript--continued-expression-p ()
"Return non-nil if the current line continues an expression."
(save-excursion
(back-to-indentation)
(let ((list-start (nth 1 (syntax-ppss))))
(and
;; This not clause is there to eliminate degenerate cases where we have
;; something that looks like a continued expression but we are in fact at
;; the beginning of the expression. Example: in `if (a) { .q(1)` when the
;; point is on the dot, the expression that follows looks like a member
;; expression but the object on which it is a member is missing. If we
;; naively treat this as a continued expression, we run into trouble
;; later. (An infinite loop.)
(not (and list-start
(save-excursion
(typescript--backward-syntactic-ws)
(backward-char)
(eq (point) list-start))))
;; Don't identify the spread syntax or rest operator as a "continuation".
(not (looking-at "\\.\\.\\."))
(or (typescript--looking-at-operator-p)
(and (progn
(typescript--backward-syntactic-ws)
(or (bobp) (backward-char))
(and (> (point) (point-min))
(save-excursion (backward-char) (not (looking-at "[/*]/")))
(typescript--looking-at-operator-p)
(and (progn (backward-char)
(not (looking-at "++\\|--\\|/[/*]"))))))))))))
(cl-defun typescript--compute-member-expression-indent ()
"Determine the indent of a member expression.
This function must be called with point located at the dot that
starts the member expression.
"
;; Find the line that has the object from which we are getting thismember.
;; And set an indent relative to that.
(while (looking-at "\\.")
(typescript--backward-syntactic-ws)
(while (eq (char-before) ?\;)
(backward-char))
(when (memq (char-before) '(?\? ?\!))
(backward-char))
(while (memq (char-before) '(?\] ?} ?\) ?>))
(if (not (eq (char-before) ?>))
(backward-list)
(backward-char)
(typescript--backward-over-generic-parameter-list))
(typescript--backward-syntactic-ws))
(if (looking-back typescript--dotted-name-re nil)
(back-to-indentation)
(typescript--forward-syntactic-ws)))
(+ (current-column) typescript-indent-level))
(defun typescript--end-of-do-while-loop-p ()
"Return non-nil if point is on the \"while\" of a do-while statement.
Otherwise, return nil. A braceless do-while statement spanning
several lines requires that the start of the loop is indented to
the same column as the current line."
(interactive)
(save-excursion
(save-match-data
(when (looking-at "\\s-*\\_")
(if (save-excursion
(skip-chars-backward "[ \t\n]*}")
(looking-at "[ \t\n]*}"))
(save-excursion
(backward-list) (forward-symbol -1) (looking-at "\\_"))
(typescript--re-search-backward "\\_" (point-at-bol) t)
(or (looking-at "\\_")
(let ((saved-indent (current-indentation)))
(while (and (typescript--re-search-backward "^\\s-*\\_<" nil t)
(/= (current-indentation) saved-indent)))
(and (looking-at "\\s-*\\_")
(not (typescript--re-search-forward
"\\_" (point-at-eol) t))
(= (current-indentation) saved-indent)))))))))
(defun typescript--ctrl-statement-indentation ()
"Helper function for `typescript--proper-indentation'.
Return the proper indentation of the current line if it starts
the body of a control statement without braces; otherwise, return
nil."
(save-excursion
(back-to-indentation)
(when (save-excursion
(and (not (eq (point-at-bol) (point-min)))
(not (looking-at "[{]"))
(progn
(typescript--re-search-backward "[[:graph:]]" nil t)
(or (eobp) (forward-char))
(when (= (char-before) ?\)) (backward-list))
(skip-syntax-backward " ")
(skip-syntax-backward "w_")
(and
(looking-at typescript--possibly-braceless-keyword-re)
;; If preceded by period, it's a method call.
(not (= (char-before) ?.))))
(not (typescript--end-of-do-while-loop-p))))
(save-excursion
(goto-char (match-beginning 0))
(+ (current-indentation) typescript-indent-level)))))
(defun typescript--get-c-offset (symbol anchor)
(let ((c-offsets-alist
(list (cons 'c typescript-comment-lineup-func))))
(c-get-syntactic-indentation (list (cons symbol anchor)))))
(defun typescript--backward-over-generic-parameter-list ()
"Search backward for the start of a generic's parameter list and move to it.
This is a utility function for
`typescript--backward-to-parameter-list'.
This function must be called with the point placed on the final >
of the generic's parameter list. It will scan backwards to find
the start. If successful, it will move the point to the start of
the list. If not, it does not move the point.
Returns nil on failure, or the position to which the point was
moved on success."
(when (eq (char-after) ?>)
(let ((depth 1))
(cl-loop named search-loop
while (> depth 0)
do (progn
(unless (re-search-backward "[<>]" nil t)
(cl-return-from search-loop nil))
(cond
((looking-at ">")
(unless (eq (char-before) ?=)
(setq depth (1+ depth))))
((looking-at "<") (setq depth (1- depth)))))
finally return (point)))))
(defun typescript--backward-to-parameter-list ()
"Search backward for the end of a parameter list and move to it.
This is a utility function for `typescript--proper-indentation'.
This function must be called with the point placed before an
opening curly brace. It will try to skip over the type
annotation that would mark the return value of a function and
move to the end of the parameter list. If it is unsuccessful, it
does not move the point. \"Unsuccessful\" here also means that
the position at which we started did not in fact mark the
beginning of a function. The curly brace belonged to some other
syntactic construct than a function.
Returns nil on failure, or the position to which the point was
moved on success."
(let ((location
(or
;; This handles the case of a function with return type annotation.
(save-excursion
(cl-loop named search-loop
do
(typescript--backward-syntactic-ws)
;; Check whether we are at "):".
(when (and (eq (char-before) ?\:)
(progn
(backward-char)
(skip-syntax-backward " ")
(eq (char-before) ?\))))
;; Success! This the end of the parameter list.
(cl-return-from search-loop (point)))
;; If we recognize a structure that belongs in a return type annotation,
;; skip back over it, or fail.
(cond
;; Arrow of a function definition, or typeguard (eg. foo is SomeClass)
((looking-back "=>\\|is" (- (point) 2))
(backward-char 2))
;; End of the parameters list of a generic.
((eq (char-before) ?>)
(backward-char)
(typescript--backward-over-generic-parameter-list))
;; Union of types, or a dot in a dotted name.
((memq (char-before) '(?| ?.))
(backward-char))
((or
;; End-delimiter of a delimited construct, for constructs
;; not handled above.
(memq (char-before) '(?\) ?} ?\" ?\]))
;; This is also dealing with dotted names. This may come
;; into play if a jump back moves over an entire dotted
;; name at once.
;;
;; The earlier test for dotted names comes into play if the
;; logic moves over one part of a dotted name at a time (which
;; is what `backward-sexp` normally does).
(and (looking-back typescript--dotted-name-re nil)
;; We don't want the loop to walk over constructs like switch (...) or for (...), etc.
(not (save-excursion
(backward-word)
(looking-at "\\_<\\(switch\\|if\\|while\\|until\\|for\\)\\_>\\(?:\\s-\\|\n\\)*(")))))
(condition-case nil
(backward-sexp)
(scan-error (cl-return-from search-loop nil))))
((looking-back typescript--number-literal-re
;; We limit the search back to the previous space or end of line (if possible)
;; to prevent the search from going over the whole buffer.
(save-excursion (re-search-backward "\\(?:\\s-\\|\n\\)" nil t)) t)
(goto-char (match-beginning 0)))
;; Otherwise, we failed to find a location.
(t
(cl-return-from search-loop nil)))))
;; This handles the case of a function without return type annotation.
(progn
(typescript--backward-syntactic-ws)
(when (eq (char-before) ?\))
(point))))))
(when location
(goto-char location))))
(defun typescript--proper-indentation (parse-status)
"Return the proper indentation for the current line."
(save-excursion
(back-to-indentation)
(let ((member-expr-p (looking-at "\\.")))
(cond ((nth 4 parse-status) ;; Inside a comment.
(typescript--get-c-offset 'c (nth 8 parse-status)))
((nth 8 parse-status) 0) ;; Inside a string.
((typescript--ctrl-statement-indentation)) ;; Control statements.
((eq (char-after) ?#) 0) ;; Looking at a pragma.
;; Inside a list of things. Note that in the TS contents, the curly braces
;; marking code blocks are "list of things".
((nth 1 parse-status)
(let ((indent-start (point))
(same-indent-p (looking-at "[]})]"))
(switch-keyword-p (looking-at "\\_\\|\\_[^:]"))
(continued-expr-p (typescript--continued-expression-p))
(list-start (nth 1 parse-status)))
(goto-char list-start)
(if (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
(progn
(skip-syntax-backward " ")
(cond
((or (typescript--backward-to-parameter-list)
(eq (char-before) ?\)))
;; Take the curly brace as marking off the body of a function.
;; In that case, we want the code that follows to see the indentation
;; that was in effect at the beginning of the function declaration, and thus
;; we want to move back over the list of function parameters.
(condition-case nil
(backward-list)
(error nil)))
((looking-back "," nil)
;; If we get here, we have a comma, spaces and an opening curly brace. (And
;; (point) is just after the comma.) We don't want to move from the current position
;; so that object literals in parameter lists are properly indented.
nil)
(t
;; In all other cases, we don't want to move from the curly brace.
(goto-char list-start)))
(back-to-indentation)
(let* ((in-switch-p (unless same-indent-p
(looking-at "\\_")))
(same-indent-p (or same-indent-p
(and switch-keyword-p
in-switch-p)))
(indent
(cond (same-indent-p
(current-column))
(continued-expr-p
(if (not member-expr-p)
(+ (current-column) (* 2 typescript-indent-level)
typescript-expr-indent-offset)
(goto-char indent-start)
(typescript--compute-member-expression-indent)))
(t
(+ (current-column) typescript-indent-level)))))
(if (and in-switch-p typescript-indent-switch-clauses)
(+ indent typescript-indent-level)
indent)))
(when (and (not same-indent-p)
typescript-indent-list-items)
(forward-char)
(skip-chars-forward " \t"))
(if continued-expr-p
(if (not member-expr-p)
(progn (back-to-indentation)
(+ (current-column) typescript-indent-level
typescript-expr-indent-offset))
(goto-char indent-start)
(typescript--compute-member-expression-indent))
(current-column)))))
((typescript--continued-expression-p) ;; Inside a continued expression.
(if member-expr-p
(typescript--compute-member-expression-indent)
(+ typescript-indent-level typescript-expr-indent-offset)))
(t 0)))))
(defun typescript-indent-line ()
"Indent the current line as typescript."
(interactive)
(save-restriction
(widen)
(let* ((parse-status
(save-excursion (syntax-ppss (point-at-bol))))
(offset (- (current-column) (current-indentation))))
(indent-line-to (typescript--proper-indentation parse-status))
(when (> offset 0) (move-to-column (+ offset (current-indentation)))))))
;;; Filling
(defun typescript-c-fill-paragraph (&optional justify)
"Fill the paragraph with `c-fill-paragraph'."
(interactive "*P")
;; Dynamically replace functions using the lexically scoped cl-letf.
;; See below for more details:
;; http://endlessparentheses.com/understanding-letf-and-how-it-replaces-flet.html
(cl-letf (((symbol-function 'c-forward-sws)
(lambda (&optional limit)
(typescript--forward-syntactic-ws limit)))
((symbol-function 'c-backward-sws)
(lambda (&optional limit)
(typescript--backward-syntactic-ws limit))))
(let ((fill-paragraph-function 'c-fill-paragraph))
(c-fill-paragraph justify))))
;; We maintain a cache of semantic information, i.e., the classes and
;; functions we've encountered so far. In order to avoid having to
;; re-parse the buffer on every change, we cache the parse state at
;; each interesting point in the buffer. Each parse state is a
;; modified copy of the previous one, or in the case of the first
;; parse state, the empty state.
;;
;; The parse state itself is just a stack of typescript--pitem
;; instances. It starts off containing one element that is never
;; closed, that is initially typescript--initial-pitem.
;;
(defun typescript--pitem-format (pitem)
(let ((name (typescript--pitem-name pitem))
(type (typescript--pitem-type pitem)))
(format "name:%S type:%S"
name
(if (atom type)
type
(plist-get type :name)))))
(defun typescript--make-merged-item (item child name-parts)
"Helper function for `typescript--splice-into-items'.
Return a new item that is the result of merging CHILD into
ITEM. NAME-PARTS is a list of parts of the name of CHILD
that we haven't consumed yet."
(typescript--debug "typescript--make-merged-item: {%s} into {%s}"
(typescript--pitem-format child)
(typescript--pitem-format item))
;; If the item we're merging into isn't a class, make it into one
(unless (consp (typescript--pitem-type item))
(typescript--debug "typescript--make-merged-item: changing dest into class")
(setq item (make-typescript--pitem
:children (list item)
;; Use the child's class-style if it's available
:type (if (atom (typescript--pitem-type child))
typescript--dummy-class-style
(typescript--pitem-type child))
:name (typescript--pitem-strname item))))
;; Now we can merge either a function or a class into a class
(cons (cond
((cdr name-parts)
(typescript--debug "typescript--make-merged-item: recursing")
;; if we have more name-parts to go before we get to the
;; bottom of the class hierarchy, call the merger
;; recursively
(typescript--splice-into-items (car item) child
(cdr name-parts)))
((atom (typescript--pitem-type child))
(typescript--debug "typescript--make-merged-item: straight merge")
;; Not merging a class, but something else, so just prepend
;; it
(cons child (car item)))
(t
;; Otherwise, merge the new child's items into those
;; of the new class
(typescript--debug "typescript--make-merged-item: merging class contents")
(append (car child) (car item))))
(cdr item)))
(defun typescript--pitem-strname (pitem)
"Last part of the name of PITEM, as a string or symbol."
(let ((name (typescript--pitem-name pitem)))
(if (consp name)
(car (last name))
name)))
(defun typescript--splice-into-items (items child name-parts)
"Splice CHILD into the `typescript--pitem' ITEMS at NAME-PARTS.
If a class doesn't exist in the tree, create it. Return
the new items list. NAME-PARTS is a list of strings given
the broken-down class name of the item to insert."
(let ((top-name (car name-parts))
(item-ptr items)
new-items last-new-item new-cons item)
(typescript--debug "typescript--splice-into-items: name-parts: %S items:%S"
name-parts
(mapcar #'typescript--pitem-name items))
(cl-assert (stringp top-name))
(cl-assert (> (length top-name) 0))
;; If top-name isn't found in items, then we build a copy of items
;; and throw it away. But that's okay, since most of the time, we
;; *will* find an instance.
(while (and item-ptr
(cond ((equal (typescript--pitem-strname (car item-ptr)) top-name)
;; Okay, we found an entry with the right name. Splice
;; the merged item into the list...
(setq new-cons (cons (typescript--make-merged-item
(car item-ptr) child
name-parts)
(cdr item-ptr)))
(if last-new-item
(setcdr last-new-item new-cons)
(setq new-items new-cons))
;; ...and terminate the loop
nil)
(t
;; Otherwise, copy the current cons and move onto the
;; text. This is tricky; we keep track of the tail of
;; the list that begins with new-items in
;; last-new-item.
(setq new-cons (cons (car item-ptr) nil))
(if last-new-item
(setcdr last-new-item new-cons)
(setq new-items new-cons))
(setq last-new-item new-cons)
;; Go to the next cell in items
(setq item-ptr (cdr item-ptr))))))
(if item-ptr
;; Yay! We stopped because we found something, not because
;; we ran out of items to search. Just return the new
;; list.
(progn
(typescript--debug "search succeeded: %S" name-parts)
new-items)
;; We didn't find anything. If the child is a class and we don't
;; have any classes to drill down into, just push that class;
;; otherwise, make a fake class and carry on.
(typescript--debug "search failed: %S" name-parts)
(cons (if (cdr name-parts)
;; We have name-parts left to process. Make a fake
;; class for this particular part...
(make-typescript--pitem
;; ...and recursively digest the rest of the name
:children (typescript--splice-into-items
nil child (cdr name-parts))
:type typescript--dummy-class-style
:name top-name)
;; Otherwise, this is the only name we have, so stick
;; the item on the front of the list
child)
items))))
(defun typescript--pitem-add-child (pitem child)
"Copy `typescript--pitem' PITEM, and push CHILD onto its list of children."
(cl-assert (integerp (typescript--pitem-h-begin child)))
(cl-assert (if (consp (typescript--pitem-name child))
(cl-loop for part in (typescript--pitem-name child)
always (stringp part))
t))
;; This trick works because we know (based on our cl-defstructs) that
;; the child list is always the first element, and so the second
;; element and beyond can be shared when we make our "copy".
(cons
(let ((name (typescript--pitem-name child))
(type (typescript--pitem-type child)))
(cond ((cdr-safe name) ; true if a list of at least two elements
;; Use slow path because we need class lookup
(typescript--splice-into-items (car pitem) child name))
((and (consp type)
(plist-get type :prototype))
;; Use slow path because we need class merging. We know
;; name is a list here because down in
;; `typescript--ensure-cache', we made sure to only add
;; class entries with lists for :name
(cl-assert (consp name))
(typescript--splice-into-items (car pitem) child name))
(t
;; Fast path
(cons child (car pitem)))))
(cdr pitem)))
;;; compilation-mode support
;; tsc supports formatting errors in two general ways: plain and
;; pretty. ("Plain" is our term for "not pretty".) In tsc versions
;; prior to 2.7, the plain and pretty formats both used the same
;; format for references into files. `typescript-tsc-error-regexp`
;; covers both plain and pretty for those versions.
;;
;; Version 2.7 changed the pretty format so as to format source code
;; references differently. This required the introduction of
;; `typescript-tsc-pretty-error-regexp`. The format of plain error
;; messages did not change. So from that version onwards,
;; `typescript-tsc-error-regexp` covers plain error messages and
;; `typescript-tsc-pretty-error-regexp` covers pretty error messages.
;; handle plain compiler-errors like the following when doing M-x compiletsc
;;
;; greeter.ts(24,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
;; greeter.ts(30,12): error TS2339: Property 'indexOf' does not exist on type 'number'.
(defconst typescript-tsc-error-regexp
(concat
"^[[:blank:]]*"
"\\([^(\r\n)]+\\)(\\([0-9]+\\),\\([0-9]+\\)):[[:blank:]]+"
"error [[:alnum:]]+: [^\r\n]+$")
"Regexp to match errors generated by tsc.")
;; handle pretty compiler-errors like the following when doing M-x compiletsc
;; test.ts:2:7 - error TS2322: Type '2' is not assignable to type 'string'.
(defconst typescript-tsc-pretty-error-regexp
(concat
"^[[:blank:]]*"
"\\([^(\r\n)]+\\):\\([0-9]+\\):\\([0-9]+\\) - [[:blank:]]*"
"error [[:alnum:]]+: [^\r\n]+$")
"Regexp to match errors generated by tsc.")
;;
;; Should handle output like:
;; src/modules/authenticator.ts[1, 83]: ' should be "
;; (quotemarks) src/modules/authenticator.ts[2, 26]: ' should be "
;; ERROR: (quotemarks) src/modules/authenticator.ts[2, 26]: ' should be "
;; WARNING: src/modules/authenticator.ts[2, 26]: ' should be "
;;
;; "(quotemarks)" it the rule name. It is produced when using the
;; "verbose" formatter. The "verbose" formatter is identical to the
;; default ("prose") formatter, except for the additional rule name.
;;
;; "ERROR:" and "WARNING:" are the severity. This was added in tslint
;; 5.0. Prior versions have no notion of severity and simply omit this
;; part.
;;
(defconst typescript-tslint-report-regexp
(concat
"^[[:blank:]]*"
;; severity ("type" in Emacs' parlance)
"\\(?:\\(?:ERROR\\|\\(WARNING\\)\\):[[:blank:]]+\\)?"
;; rule name
"\\((.*)[[:blank:]]+\\)?"
;; filename
"\\([^(\r\n)]+\\)"
"\\["
;; line
"\\([[:digit:]]+\\)"
", "
;; column
"\\([[:digit:]]+\\)"
"\\]: "
;; message
".*$")
"Regexp to match reports generated by tslint.")
(defconst typescript-nglint-error-regexp
(concat
;; severity ("type" in Emacs' parlance)
"ERROR:[[:blank:]]+"
;; filename
"\\([^(\r\n)]+\\)"
":"
;; line
"\\([[:digit:]]+\\)"
":"
;; column
"\\([[:digit:]]+\\)"
" - "
;; message
".*$"))
(defconst typescript-nglint-warning-regexp
(concat
;; severity ("type" in Emacs' parlance)
"WARNING:[[:blank:]]+"
;; filename
"\\([^(\r\n)]+\\)"
":"
;; line
"\\([[:digit:]]+\\)"
":"
;; column
"\\([[:digit:]]+\\)"
" - "
;; message
".*$"))
(dolist
(regexp
`((typescript-tsc
,typescript-tsc-error-regexp
1 2 3 2)
(typescript-tsc-pretty
,typescript-tsc-pretty-error-regexp
1 2 3 2)
(typescript-tslint
,typescript-tslint-report-regexp
3 4 5 (1))
(typescript-nglint-error
,typescript-nglint-error-regexp
1 2 3 2)
(typescript-nglint-warning
,typescript-nglint-warning-regexp
1 2 3 1)))
(add-to-list 'compilation-error-regexp-alist-alist regexp)
(add-to-list 'compilation-error-regexp-alist (car regexp)))
;;; Main Function
;;;###autoload
(define-derived-mode typescript-mode prog-mode "TypeScript"
"Major mode for editing typescript.
Key bindings:
\\{typescript-mode-map}"
:group 'typescript
:syntax-table typescript-mode-syntax-table
(setq-local indent-line-function 'typescript-indent-line)
(setq-local beginning-of-defun-function 'typescript-beginning-of-defun)
(setq-local end-of-defun-function 'typescript-end-of-defun)
(setq-local open-paren-in-column-0-is-defun-start nil)
(setq-local font-lock-defaults (list typescript--font-lock-keywords))
(setq-local font-lock-multiline t)
(setq-local syntax-propertize-function #'typescript-syntax-propertize)
(setq-local parse-sexp-ignore-comments t)
(setq-local parse-sexp-lookup-properties t)
;; Comments
(setq-local comment-start "// ")
(setq-local comment-end "")
(setq-local fill-paragraph-function 'typescript-c-fill-paragraph)
;; Parse cache
(add-hook 'before-change-functions #'typescript--flush-caches t t)
;; Frameworks
(typescript--update-quick-match-re)
;; for filling, pretend we're cc-mode
(setq c-comment-prefix-regexp "//+\\|\\**"
c-paragraph-start "$"
c-paragraph-separate "$"
c-block-comment-prefix "* "
c-block-comment-ender-regexp "\\*/"
c-line-comment-starter "//"
c-comment-start-regexp "/[*/]\\|\\s!"
comment-start-skip "\\(//+\\|/\\*+\\)\\s *")
(setq-local electric-indent-chars
(append "{}():;," electric-indent-chars))
(setq-local electric-layout-rules
'((?\; . after) (?\{ . after) (?\} . before)))
(let ((c-buffer-is-cc-mode t))
;; FIXME: These are normally set by `c-basic-common-init'. Should
;; we call it instead? (Bug#6071)
(make-local-variable 'paragraph-start)
(make-local-variable 'paragraph-separate)
(make-local-variable 'paragraph-ignore-fill-prefix)
(make-local-variable 'adaptive-fill-mode)
(make-local-variable 'adaptive-fill-regexp)
(c-setup-paragraph-variables))
(add-hook 'post-self-insert-hook
#'typescript--post-self-insert-function)
(setq-local syntax-begin-function #'typescript--syntax-begin-function))
;; Set our custom predicate for flyspell prog mode
(put 'typescript-mode 'flyspell-mode-predicate
'typescript--flyspell-mode-predicate)
;;;###autoload
(eval-after-load 'folding
'(when (fboundp 'folding-add-to-marks-list)
(folding-add-to-marks-list 'typescript-mode "// {{{" "// }}}" )))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescript-mode))
(provide 'typescript-mode)
;;; typescript-mode.el ends here