A compound of formula or a pharmaceutically acceptable salt thereof, wherein, W is C(R 7) or N; R 1 and R 2 are each independently selected from H, halogen, amino, hydroxy, cyano, C 1-6 alkyl, C 3-6 cycloalkyl, 3-10 membered heterocycloalkyl, 6-12 membered aryl or 5-12 membered heteroaryl, said amino, C 1-6 alkyl, C 3-6 cycloalkyl, 3-10 membered heterocycloalkyl, 6-12 membered aryl or 5-12 membered heteroaryl is optionally substituted with R 8; R 3, R 4 and R 7 are each independently selected from H, halogen, amino, hydroxy, cyano, C 1-6 alkyl, C 3-6 cycloalkyl or 3-6 membered heterocycloalkyl, said amino, C 1-6 alkyl, C 3-6 cycloalkyl or 3-6 membered heterocycloalkyl is optionally substituted with R 9; R 5 is selected from H, C 1-6 alkyl, C 3-6 cycloalkyl or 3-6 membered heterocycloalkyl, C 1-6 alkyl C, C 3-6 cycloalkyl C or 3-6 membered heterocycloalkyl C, phenyl C, 5-6 membered heteroaryl C, C 1-6 alkyl SO 2, C 3-6 cycloalkyl SO 2 or 3-6 membered heterocycloalkyl SO 2, phenyl SO 2 or 5-6 membered heteroaryl SO 2, said C 1-6 alkyl, C 3-6 cycloalkyl or 3-6 membered heterocycloalkyl, C 1-6 alkyl C, C 3-6 cycloalkyl C or 3-6 membered heterocycloalkyl C, phenyl C, 5-6 membered heteroaryl C, C 1-6 alkyl SO 2, C 3-6 cycloalkyl SO 2 or 3-6 membered heterocycloalkyl SO 2, phenyl SO 2 or 5-6 membered heteroaryl SO 2 is optionally substituted with R 9; X is selected from 3-12 membered ring with a loss of hydrogen atoms at any two positions, which is optionally substituted with R 9; L is selected from bond, NH, O, S, SO, SO 2, C, OC, C O, C NH, NHSO 2, SO 2 NH, NHC NH or NHSO 2 NH; R 6 is selected from H, halogen, amino, hydroxy, cyano, C 1-6 alkyl, C 3-10 cycloalkyl or 3-10 membered heterocycloalkyl, said amino, C 1-6 alkyl, C 3-10 cycloalkyl or 3-10 membered heterocycloalkyl is optionally substituted with R 10; R 8 and R 9 are each independently selected from halogen, amino, hydroxy, cyano, C 1-3 alkyl, C 1-3 alkoxy or COOH; R 10 is selected from halogen, amino, hydroxy, cyano, halogenated C 1-3 alkyl, COOH, =, C 1-6 alkyl, C 1-6 alkyl SO 2, C 3-6 cycloalkyl or 3-10 membered heterocycloalkyl; and, at least one of R 1 and R 2 is selected from 6-12 membered aryl or 5-12 membered heteroaryl, said 6-12 membered aryl or 5-12 membered heteroaryl is optionally substituted with R 8. W is C(R 7) or N; R 1 and R 2 are each independently selected from H, halogen, amino, hydroxy, cyano, C 1-6 alkyl, C 3-6 cycloalkyl, 3-10 membered heterocycloalkyl, 6-12 membered aryl or 5-12 membered heteroaryl, said amino, C 1-6 alkyl, C 3-6 cycloalkyl, 3-10 membered heterocycloalkyl, 6-12 membered aryl or 5-12 membered heteroaryl is optionally substituted with R 8; R 3, R 4 and R 7 are each independently selected from H, halogen, amino, hydroxy, cyano, C 1-6 alkyl, C 3-6 cycloalkyl or 3-6 membered heterocycloalkyl, said amino, C 1-6 alkyl, C 3-6 cycloalkyl or 3-6 membered heterocycloalkyl is optionally substituted with R 9; R 5 is selected from H, C 1-6 alkyl, C 3-6 cycloalkyl or 3-6 membered heterocycloalkyl, C 1-6 alkyl C, C 3-6 cycloalkyl C or 3-6 membered heterocycloalkyl C, phenyl C, 5-6 membered heteroaryl C, C 1-6 alkyl SO 2, C 3-6 cycloalkyl SO 2 or 3-6 membered heterocycloalkyl SO 2, phenyl SO 2 or 5-6 membered heteroaryl SO 2, said C 1-6 alkyl, C 3-6 cycloalkyl or 3-6 membered heterocycloalkyl, C 1-6 alkyl C, C 3-6 cycloalkyl C or 3-6 membered heterocycloalkyl C, phenyl C, 5-6 membered heteroaryl C, C 1-6 alkyl SO 2, C 3-6 cycloalkyl SO 2 or 3-6 membered heterocycloalkyl SO 2, phenyl SO 2 or 5-6 membered heteroaryl SO 2 is optionally substituted with R 9; X is selected from 3-12 membered ring with a loss of hydrogen atoms at any two positions, which is optionally substituted with R 9; L is selected from bond, NH, O, S, SO, SO 2, C, OC, C O, C NH, NHSO 2, SO 2 NH, NHC NH or NHSO 2 NH; R 6 is selected from H, halogen, amino, hydroxy, cyano, C 1-6 alkyl, C 3-10 cycloalkyl or 3-10 membered heterocycloalkyl, said amino, C 1-6 alkyl, C 3-10 cycloalkyl or 3-10 membered heterocycloalkyl is optionally substituted with R 10; R 8 and R 9 are each independently selected from halogen, amino, hydroxy, cyano, C 1-3 alkyl, C 1-3 alkoxy or COOH; R 10 is selected from halogen, amino, hydroxy, cyano, halogenated C 1-3 alkyl, COOH, =, C 1-6 alkyl, C 1-6 alkyl SO 2, C 3-6 cycloalkyl or 3-10 membered heterocycloalkyl; and, at least one of R 1 and R 2 is selected from 6-12 membered aryl or 5-12 membered heteroaryl, said 6-12 membered aryl or 5-12 membered heteroaryl is optionally substituted with R 8.