@@ -1779,12 +1779,12 @@ namespace ts {
1779
1779
function getJSSyntacticDiagnosticsForFile ( sourceFile : SourceFile ) : DiagnosticWithLocation [ ] {
1780
1780
return runWithCancellationToken ( ( ) => {
1781
1781
const diagnostics : DiagnosticWithLocation [ ] = [ ] ;
1782
- let parent : Node = sourceFile ;
1783
- walk ( sourceFile ) ;
1782
+ walk ( sourceFile , sourceFile ) ;
1783
+ forEachChildRecursively ( sourceFile , walk , walkArray ) ;
1784
1784
1785
1785
return diagnostics ;
1786
1786
1787
- function walk ( node : Node ) {
1787
+ function walk ( node : Node , parent : Node ) {
1788
1788
// Return directly from the case if the given node doesnt want to visit each child
1789
1789
// Otherwise break to visit each child
1790
1790
@@ -1794,7 +1794,7 @@ namespace ts {
1794
1794
case SyntaxKind . MethodDeclaration :
1795
1795
if ( ( < ParameterDeclaration | PropertyDeclaration | MethodDeclaration > parent ) . questionToken === node ) {
1796
1796
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . The_0_modifier_can_only_be_used_in_TypeScript_files , "?" ) ) ;
1797
- return ;
1797
+ return "skip" ;
1798
1798
}
1799
1799
// falls through
1800
1800
case SyntaxKind . MethodSignature :
@@ -1808,73 +1808,68 @@ namespace ts {
1808
1808
// type annotation
1809
1809
if ( ( < FunctionLikeDeclaration | VariableDeclaration | ParameterDeclaration | PropertyDeclaration > parent ) . type === node ) {
1810
1810
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . Type_annotations_can_only_be_used_in_TypeScript_files ) ) ;
1811
- return ;
1811
+ return "skip" ;
1812
1812
}
1813
1813
}
1814
1814
1815
1815
switch ( node . kind ) {
1816
1816
case SyntaxKind . ImportClause :
1817
1817
if ( ( node as ImportClause ) . isTypeOnly ) {
1818
1818
diagnostics . push ( createDiagnosticForNode ( node . parent , Diagnostics . _0_declarations_can_only_be_used_in_TypeScript_files , "import type" ) ) ;
1819
- return ;
1819
+ return "skip" ;
1820
1820
}
1821
1821
break ;
1822
1822
case SyntaxKind . ExportDeclaration :
1823
1823
if ( ( node as ExportDeclaration ) . isTypeOnly ) {
1824
1824
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . _0_declarations_can_only_be_used_in_TypeScript_files , "export type" ) ) ;
1825
- return ;
1825
+ return "skip" ;
1826
1826
}
1827
1827
break ;
1828
1828
case SyntaxKind . ImportEqualsDeclaration :
1829
1829
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . import_can_only_be_used_in_TypeScript_files ) ) ;
1830
- return ;
1830
+ return "skip" ;
1831
1831
case SyntaxKind . ExportAssignment :
1832
1832
if ( ( < ExportAssignment > node ) . isExportEquals ) {
1833
1833
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . export_can_only_be_used_in_TypeScript_files ) ) ;
1834
- return ;
1834
+ return "skip" ;
1835
1835
}
1836
1836
break ;
1837
1837
case SyntaxKind . HeritageClause :
1838
1838
const heritageClause = < HeritageClause > node ;
1839
1839
if ( heritageClause . token === SyntaxKind . ImplementsKeyword ) {
1840
1840
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . implements_clauses_can_only_be_used_in_TypeScript_files ) ) ;
1841
- return ;
1841
+ return "skip" ;
1842
1842
}
1843
1843
break ;
1844
1844
case SyntaxKind . InterfaceDeclaration :
1845
1845
const interfaceKeyword = tokenToString ( SyntaxKind . InterfaceKeyword ) ;
1846
1846
Debug . assertIsDefined ( interfaceKeyword ) ;
1847
1847
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . _0_declarations_can_only_be_used_in_TypeScript_files , interfaceKeyword ) ) ;
1848
- return ;
1848
+ return "skip" ;
1849
1849
case SyntaxKind . ModuleDeclaration :
1850
1850
const moduleKeyword = node . flags & NodeFlags . Namespace ? tokenToString ( SyntaxKind . NamespaceKeyword ) : tokenToString ( SyntaxKind . ModuleKeyword ) ;
1851
1851
Debug . assertIsDefined ( moduleKeyword ) ;
1852
1852
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . _0_declarations_can_only_be_used_in_TypeScript_files , moduleKeyword ) ) ;
1853
- return ;
1853
+ return "skip" ;
1854
1854
case SyntaxKind . TypeAliasDeclaration :
1855
1855
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . Type_aliases_can_only_be_used_in_TypeScript_files ) ) ;
1856
- return ;
1856
+ return "skip" ;
1857
1857
case SyntaxKind . EnumDeclaration :
1858
1858
const enumKeyword = Debug . checkDefined ( tokenToString ( SyntaxKind . EnumKeyword ) ) ;
1859
1859
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . _0_declarations_can_only_be_used_in_TypeScript_files , enumKeyword ) ) ;
1860
- return ;
1860
+ return "skip" ;
1861
1861
case SyntaxKind . NonNullExpression :
1862
1862
diagnostics . push ( createDiagnosticForNode ( node , Diagnostics . Non_null_assertions_can_only_be_used_in_TypeScript_files ) ) ;
1863
- return ;
1863
+ return "skip" ;
1864
1864
case SyntaxKind . AsExpression :
1865
1865
diagnostics . push ( createDiagnosticForNode ( ( node as AsExpression ) . type , Diagnostics . Type_assertion_expressions_can_only_be_used_in_TypeScript_files ) ) ;
1866
- return ;
1866
+ return "skip" ;
1867
1867
case SyntaxKind . TypeAssertionExpression :
1868
1868
Debug . fail ( ) ; // Won't parse these in a JS file anyway, as they are interpreted as JSX.
1869
1869
}
1870
-
1871
- const prevParent = parent ;
1872
- parent = node ;
1873
- forEachChild ( node , walk , walkArray ) ;
1874
- parent = prevParent ;
1875
1870
}
1876
1871
1877
- function walkArray ( nodes : NodeArray < Node > ) {
1872
+ function walkArray ( nodes : NodeArray < Node > , parent : Node ) {
1878
1873
if ( parent . decorators === nodes && ! options . experimentalDecorators ) {
1879
1874
diagnostics . push ( createDiagnosticForNode ( parent , Diagnostics . Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_in_your_tsconfig_or_jsconfig_to_remove_this_warning ) ) ;
1880
1875
}
@@ -1892,14 +1887,15 @@ namespace ts {
1892
1887
// Check type parameters
1893
1888
if ( nodes === ( < DeclarationWithTypeParameterChildren > parent ) . typeParameters ) {
1894
1889
diagnostics . push ( createDiagnosticForNodeArray ( nodes , Diagnostics . Type_parameter_declarations_can_only_be_used_in_TypeScript_files ) ) ;
1895
- return ;
1890
+ return "skip" ;
1896
1891
}
1897
1892
// falls through
1898
1893
1899
1894
case SyntaxKind . VariableStatement :
1900
1895
// Check modifiers
1901
1896
if ( nodes === parent . modifiers ) {
1902
- return checkModifiers ( parent . modifiers , parent . kind === SyntaxKind . VariableStatement ) ;
1897
+ checkModifiers ( parent . modifiers , parent . kind === SyntaxKind . VariableStatement ) ;
1898
+ return "skip" ;
1903
1899
}
1904
1900
break ;
1905
1901
case SyntaxKind . PropertyDeclaration :
@@ -1910,14 +1906,14 @@ namespace ts {
1910
1906
diagnostics . push ( createDiagnosticForNode ( modifier , Diagnostics . The_0_modifier_can_only_be_used_in_TypeScript_files , tokenToString ( modifier . kind ) ) ) ;
1911
1907
}
1912
1908
}
1913
- return ;
1909
+ return "skip" ;
1914
1910
}
1915
1911
break ;
1916
1912
case SyntaxKind . Parameter :
1917
1913
// Check modifiers of parameter declaration
1918
1914
if ( nodes === ( < ParameterDeclaration > parent ) . modifiers ) {
1919
1915
diagnostics . push ( createDiagnosticForNodeArray ( nodes , Diagnostics . Parameter_modifiers_can_only_be_used_in_TypeScript_files ) ) ;
1920
- return ;
1916
+ return "skip" ;
1921
1917
}
1922
1918
break ;
1923
1919
case SyntaxKind . CallExpression :
@@ -1929,14 +1925,10 @@ namespace ts {
1929
1925
// Check type arguments
1930
1926
if ( nodes === ( < NodeWithTypeArguments > parent ) . typeArguments ) {
1931
1927
diagnostics . push ( createDiagnosticForNodeArray ( nodes , Diagnostics . Type_arguments_can_only_be_used_in_TypeScript_files ) ) ;
1932
- return ;
1928
+ return "skip" ;
1933
1929
}
1934
1930
break ;
1935
1931
}
1936
-
1937
- for ( const node of nodes ) {
1938
- walk ( node ) ;
1939
- }
1940
1932
}
1941
1933
1942
1934
function checkModifiers ( modifiers : NodeArray < Modifier > , isConstValid : boolean ) {
0 commit comments